From a4ebfb19b6bf01e0b25f543d9dc4ab5d12120095 Mon Sep 17 00:00:00 2001 From: Derek Smith Date: Fri, 11 Aug 2023 09:55:57 -0400 Subject: [PATCH] Move backup_path.sh up a level, refactors. --- www/go.sh | 90 +++++++++++++-------------------------- www/stop_docker_stacks.sh | 9 ---- 2 files changed, 30 insertions(+), 69 deletions(-) diff --git a/www/go.sh b/www/go.sh index 39384d2..171df48 100755 --- a/www/go.sh +++ b/www/go.sh @@ -3,11 +3,6 @@ set -exu cd "$(dirname "$0")" -# redirect all docker commands to the remote host. -DOCKER_HOST="ssh://ubuntu@$WWW_FQDN" -export DOCKER_HOST="$DOCKER_HOST" - - # Create the nginx config file which covers all domainys. bash -c ./stub/nginx_config.sh @@ -77,53 +72,49 @@ for DOMAIN_NAME in ${DOMAIN_LIST//,/ }; do done -./stop_docker_stacks.sh - # TODO check if there are any other stacks that are left running (other than reverse proxy) # if so, this may mean the user has disabled one or more domains and that existing sites/services # are still running. We should prompt the user of this and quit. They have to go manually docker stack remove these. +STACKS_STILL_RUNNING=false if [[ $(docker stack list | wc -l) -gt 2 ]]; then - echo "WARNING! You still have stacks running. If you have modified the SITES list, you may need to go remove the docker stacks runnong the remote machine." - echo "exiting." - exit 1 + echo "WARNING! You still have stacks running. If you have modified the SITES list," + echo " you may need to go remove the docker stacks running the remote machine." + STACKS_STILL_RUNNING=true fi -# ok, the backend stacks are stopped. -if [ "$RESTART_FRONT_END" = true ]; then +# generate the certs and grab a backup +if [ "$RUN_CERT_RENEWAL" = true ] && [ "$RESTORE_CERTS" = false ] && [ "$STACKS_STILL_RUNNING" = false ]; then + ./generate_certs.sh +fi - # generate the certs and grab a backup - if [ "$RUN_CERT_RENEWAL" = true ] && [ "$RESTORE_CERTS" = false ]; then - if [ "$STOP_SERVICES" = false ]; then - ./generate_certs.sh - fi - 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" - # 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 ../../deployment_defaults.sh + source ../project_defaults.sh + source "$SITE_PATH/site.conf" + source ../domain_env.sh - # source the site path so we know what features it has. - source ../../deployment_defaults.sh - source ../project_defaults.sh - source "$SITE_PATH/site.conf" - source ../domain_env.sh + # these variable are used by both backup/restore scripts. + export REMOTE_BACKUP_PATH="$REMOTE_BACKUP_PATH/www/$APP/$DOMAIN_IDENTIFIER" + export REMOTE_SOURCE_BACKUP_PATH="$REMOTE_DATA_PATH/$APP/$DOMAIN_NAME" - # these variable are used by both backup/restore scripts. - export REMOTE_BACKUP_PATH="$REMOTE_BACKUP_PATH/www/$APP/$DOMAIN_IDENTIFIER" - export REMOTE_SOURCE_BACKUP_PATH="$REMOTE_DATA_PATH/$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" - # 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" - - # we grab a backup of the certs unless we're restoring. - if [ "$RESTORE_CERTS" = true ]; then - ./restore_path.sh - else + # we grab a backup of the certs unless we're restoring. + if [ "$RESTORE_CERTS" = true ]; then + ./restore_path.sh + else + if [ "$BACKUP_WWW_APPS" = true ]; then ./backup_path.sh fi + fi done # nginx gets deployed first since it "owns" the docker networks of downstream services. @@ -134,24 +125,3 @@ done ./stub/nextcloud_yml.sh ./stub/gitea_yml.sh ./stub/nostr_yml.sh - - - -# # start a browser session; point it to port 80 to ensure HTTPS redirect. -# # WWW_FQDN is in our certificate, so we resolve to that. -# wait-for-it -t 320 "$WWW_FQDN:80" -# wait-for-it -t 320 "$WWW_FQDN:443" - -# # open bowser tabs. -# if [ "$DEPLOY_GHOST" = true ]; then -# xdg-open "http://$WWW_FQDN" > /dev/null 2>&1 -# fi - -# if [ "$DEPLOY_NEXTCLOUD" = true ]; then -# xdg-open "http://$NEXTCLOUD_FQDN" > /dev/null 2>&1 -# fi - -# if [ "$DEPLOY_GITEA" = true ]; then -# xdg-open "http://$GITEA_FQDN" > /dev/null 2>&1 -# fi - diff --git a/www/stop_docker_stacks.sh b/www/stop_docker_stacks.sh index 10b3e67..756329e 100755 --- a/www/stop_docker_stacks.sh +++ b/www/stop_docker_stacks.sh @@ -37,15 +37,6 @@ for DOMAIN_NAME in ${DOMAIN_LIST//,/ }; do if [ ! -d "$LOCAL_BACKUP_PATH" ]; then mkdir -p "$LOCAL_BACKUP_PATH" fi - - if [ "$RESTORE_WWW" = true ]; then - ./restore_path.sh - fi - - if [ "$BACKUP_APPS" = true ]; then - # if we're not restoring, then we may or may not back up. - ./backup_path.sh - fi done done done