From 83f7c28a0c2939275272bc1b81dfea523366fc44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Torrero=20Marijnissen?= Date: Thu, 13 May 2021 08:53:24 +0100 Subject: [PATCH] Add deploy.sh script helper --- hack/README.md | 28 +++++++++++++++++++++++ hack/deploy.sh | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 hack/README.md create mode 100755 hack/deploy.sh diff --git a/hack/README.md b/hack/README.md new file mode 100644 index 000000000..d419a2cfa --- /dev/null +++ b/hack/README.md @@ -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@] [deploy-agent*|deploy-web]` + + - `[username]@` + The IP address of the host where we are deploying `trento` and `consul` on. + + - `` + 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 diff --git a/hack/deploy.sh b/hack/deploy.sh new file mode 100755 index 000000000..dc692de64 --- /dev/null +++ b/hack/deploy.sh @@ -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 [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