From 1bc685fa7450fa0342618f0a66e1260ad81d90e2 Mon Sep 17 00:00:00 2001 From: Derek Smith Date: Sun, 25 Dec 2022 12:59:02 -0500 Subject: [PATCH] Control flow updates. --- deploy.sh | 1 + deployment/www/restore_path.sh | 3 +- deployment/www/stop_docker_stacks.sh | 94 +++++++++++++--------------- migrate.sh | 13 +++- 4 files changed, 59 insertions(+), 52 deletions(-) diff --git a/deploy.sh b/deploy.sh index f7378d5..67bc505 100755 --- a/deploy.sh +++ b/deploy.sh @@ -23,6 +23,7 @@ RECONFIGURE_BTCPAY_SERVER=false CLUSTER_NAME="$(lxc remote get-default)" STOP_SERVICES=false USER_SAYS_YES=false +RESTART_FRONT_END=false # grab any modifications from the command line. for i in "$@"; do diff --git a/deployment/www/restore_path.sh b/deployment/www/restore_path.sh index 0f0c561..c589bca 100755 --- a/deployment/www/restore_path.sh +++ b/deployment/www/restore_path.sh @@ -34,4 +34,5 @@ scp -r "$LOCAL_BACKUP_PATH" "$PRIMARY_WWW_FQDN:$REMOTE_BACKUP_PATH" # now we run duplicity to restore the archive. ssh "$PRIMARY_WWW_FQDN" sudo PASSPHRASE="$DUPLICITY_BACKUP_PASSPHRASE" duplicity --force restore "file://$REMOTE_BACKUP_PATH/$APP" "$REMOTE_SOURCE_BACKUP_PATH/" -ssh "$PRIMARY_WWW_FQDN" sudo chown ubuntu:ubuntu "$REMOTE_BACKUP_PATH" \ No newline at end of file +# reset folder owner to ubuntu +ssh "$PRIMARY_WWW_FQDN" sudo chown ubuntu:ubuntu "$REMOTE_HOME/$APP" \ No newline at end of file diff --git a/deployment/www/stop_docker_stacks.sh b/deployment/www/stop_docker_stacks.sh index a955817..23b7595 100755 --- a/deployment/www/stop_docker_stacks.sh +++ b/deployment/www/stop_docker_stacks.sh @@ -48,55 +48,51 @@ for DOMAIN_NAME in ${DOMAIN_LIST//,/ }; do done done -# remove the nginx stack -if docker stack list --format "{{.Name}}" | grep -q reverse-proxy; then - sleep 2 +if [ "$RESTART_FRONT_END" = true ]; then + # remove the nginx stack + if docker stack list --format "{{.Name}}" | grep -q reverse-proxy; then + sleep 2 - docker stack rm reverse-proxy + docker stack rm reverse-proxy - # wait for all docker containers to stop. - # TODO see if there's a way to check for this. - sleep 15 - -fi - -# -if [ "$STOP_SERVICES" = true ]; then - echo "STOPPING as indicated by the --stop flag." - exit 0 -fi - -# generate the certs and grab a backup -if [ "$RUN_CERT_RENEWAL" = true ]; then - ./generate_certs.sh -fi - -# let's backup all our letsencrypt certs -export APP="letsencrypt" -for DOMAIN_NAME in ${DOMAIN_LIST//,/ }; do - export DOMAIN_NAME="$DOMAIN_NAME" - export SITE_PATH="$SITES_PATH/$DOMAIN_NAME" - - # source the site path so we know what features it has. - source "$RESPOSITORY_PATH/reset_env.sh" - source "$SITE_PATH/site_definition" - source "$RESPOSITORY_PATH/domain_env.sh" - - # these variable are used by both backup/restore scripts. - export REMOTE_BACKUP_PATH="$REMOTE_HOME/backups/www/$APP/$DOMAIN_IDENTIFIER" - export REMOTE_SOURCE_BACKUP_PATH="$REMOTE_HOME/$APP/$DOMAIN_NAME" - - # ensure our local backup path exists so we can pull down the duplicity archive to the management machine. - export LOCAL_BACKUP_PATH="$SITE_PATH/backups/www/$APP" - mkdir -p "$LOCAL_BACKUP_PATH" - - if [ "$RESTORE_WWW" = true ]; then - sleep 5 - echo "STARTING restore_path.sh for letsencrypt." - ./restore_path.sh - #ssh "$PRIMARY_WWW_FQDN" sudo chown ubuntu:ubuntu "$REMOTE_HOME/$APP" - elif [ "$BACKUP_APPS" = true ]; then - # if we're not restoring, then we may or may not back up. - ./backup_path.sh + # wait for all docker containers to stop. + # TODO see if there's a way to check for this. + sleep 15 + fi -done + + # generate the certs and grab a backup + if [ "$RUN_CERT_RENEWAL" = true ]; then + ./generate_certs.sh + fi + + # let's backup all our letsencrypt certs + export APP="letsencrypt" + for DOMAIN_NAME in ${DOMAIN_LIST//,/ }; do + export DOMAIN_NAME="$DOMAIN_NAME" + export SITE_PATH="$SITES_PATH/$DOMAIN_NAME" + + # source the site path so we know what features it has. + source "$RESPOSITORY_PATH/reset_env.sh" + source "$SITE_PATH/site_definition" + source "$RESPOSITORY_PATH/domain_env.sh" + + # these variable are used by both backup/restore scripts. + export REMOTE_BACKUP_PATH="$REMOTE_HOME/backups/www/$APP/$DOMAIN_IDENTIFIER" + export REMOTE_SOURCE_BACKUP_PATH="$REMOTE_HOME/$APP/$DOMAIN_NAME" + + # ensure our local backup path exists so we can pull down the duplicity archive to the management machine. + export LOCAL_BACKUP_PATH="$SITE_PATH/backups/www/$APP" + mkdir -p "$LOCAL_BACKUP_PATH" + + if [ "$RESTORE_WWW" = true ]; then + sleep 5 + echo "STARTING restore_path.sh for letsencrypt." + ./restore_path.sh + #ssh "$PRIMARY_WWW_FQDN" sudo chown ubuntu:ubuntu "$REMOTE_HOME/$APP" + elif [ "$BACKUP_APPS" = true ]; then + # if we're not restoring, then we may or may not back up. + ./backup_path.sh + fi + done +fi diff --git a/migrate.sh b/migrate.sh index d837f89..3c823fb 100755 --- a/migrate.sh +++ b/migrate.sh @@ -6,8 +6,17 @@ cd "$(dirname "$0")" CURRENT_CLUSTER="$(lxc remote get-default)" if echo "$CURRENT_CLUSTER" | grep -q "production"; then - echo "ERROR: YOU MUST COMMENT THIS OUT BEFORE YOU CAN RUN MIGRATE ON PROUDCTION/." - exit 1 + echo "WARNING: You are running a migration procedure on a production system." + echo "" + + + RESPONSE= + read -r -p " Are you sure you want to continue (y) ": RESPONSE + if [ "$RESPONSE" != "y" ]; then + echo "STOPPING." + exit 1 + fi + fi source ./defaults.sh