Skip to content
This repository has been archived by the owner on May 30, 2022. It is now read-only.

Add deploy.sh script helper #60

Merged
merged 1 commit into from
May 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions hack/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

# Hacks

This directory is a collection of scripts & utilities that can assist developers
and users interested in testing and experimenting with Trento.

## deploy.sh
`deploy.sh` is a very simple script that will attempt to copy the `trento` binary
and the `consul` binary to a remote server and start both services

### Requirements
The machines that we are deploying to require to have `rsync` as well as a running
SSH server.

### Usage
`./deploy.sh [username@]<target-server-ip> <consul-ip> [deploy-agent*|deploy-web]`

- `[username]@<target-server-ip>`
The IP address of the host where we are deploying `trento` and `consul` on.

- `<consul-ip>`
The IP of the consul server that we are connecting to. When `deploy-web` is
used in the next field, this is ignored.

- `[deploy-agent|deploy-web]`
`deploy-agent` causes to deploy the `consul` and `trento` agents
while
`deploy-web` causes to deploy the web server as well as a `consul` server instance
61 changes: 61 additions & 0 deletions hack/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/bin/bash
TARGET_HOST=$1
CONSUL_HOST=$2
ACTION=$3
TRENTO_BIN="trento"
CONSUL_BIN="consul"
TRENTO_PATH="/srv/trento/"
CONSUL_PATH="/srv/consul/"
EXAMPLES_PATH="$TRENTO_PATH/examples"
TARGET_USER="root"
CONSUL_DATA_DIR="consul-agent-data"

# Abort when any command in the script fails
set -e

# Abort if no input params
if [ $# -lt 2 ] ; then
echo "Usage: ./deploy.sh <target-server-ip> <consul-ip> [deploy-agent*|deploy-web]"
exit 1
fi

# If no action is provided, we assume deploy-agent
if test "X$ACTION" == "X" ; then
ACTION="deploy-agent"
fi

stop_process () {
echo "Checking if process $2 is running in $1..."
while ssh "$TARGET_USER@$TARGET_HOST" pgrep -x "$2" > /dev/null
do
echo "Attempting to stop $2 process on $1..."
ssh "$TARGET_USER@$TARGET_HOST" killall "$2"
sleep 2
done
}

# Stop old processes
stop_process "$TARGET_HOST" "trento"
stop_process "$TARGET_HOST" "consul"

# Create directory structure if it doesn't exist
ssh "$TARGET_USER@$TARGET_HOST" mkdir -p "$TRENTO_PATH" || true
ssh "$TARGET_USER@$TARGET_HOST" mkdir -p "$CONSUL_PATH/consul.d" || true

# Upload new binaries & examples
rsync -av ./$TRENTO_BIN "$TARGET_USER@$TARGET_HOST:/$TRENTO_PATH"
rsync -av ./$CONSUL_BIN "$TARGET_USER@$TARGET_HOST:/$CONSUL_PATH"
rsync -av ./examples "$TARGET_USER@$TARGET_HOST:/$EXAMPLES_PATH"

# Give them execution permission
ssh "$TARGET_USER@$TARGET_HOST" chmod +x "$TRENTO_PATH/$TRENTO_BIN"
ssh "$TARGET_USER@$TARGET_HOST" chmod +x "$CONSUL_PATH/$CONSUL_BIN"

# Start 'em
if [ "$ACTION" = "deploy-agent" ] ; then
ssh "$TARGET_USER@$TARGET_HOST" -f "nohup $CONSUL_PATH/$CONSUL_BIN agent -bind=$TARGET_HOST -data-dir=$CONSUL_DATA_DIR -config-dir=$CONSUL_PATH/consul.d -retry-join=$CONSUL_HOST -ui > /dev/null 2>&1"
ssh "$TARGET_USER@$TARGET_HOST" -f "nohup $TRENTO_PATH/$TRENTO_BIN agent start -n $TARGET_HOST --config-dir=$CONSUL_PATH/consul.d --consul-template=$EXAMPLES_PATH/trento-config.tpl $EXAMPLES_PATH/azure-rules.yaml > /dev/null 2>&1"
elif [ "$ACTION" = "deploy-web" ] ; then
ssh "$TARGET_USER@$TARGET_HOST" -f "nohup $CONSUL_PATH/$CONSUL_BIN agent -server -bootstrap-expect=1 -bind=$TARGET_HOST -data-dir=$CONSUL_DATA_DIR -ui > /dev/null 2>&1"
ssh "$TARGET_USER@$TARGET_HOST" -f "nohup $TRENTO_PATH/$TRENTO_BIN web serve > /dev/null 2>&1"
fi