sovereign-stack/deployment/www/stop_docker_stacks.sh

99 lines
3.4 KiB
Bash
Raw Normal View History

2022-09-28 17:59:01 +00:00
#!/bin/bash
2022-10-29 15:34:17 +00:00
set -eu
2022-09-28 17:59:01 +00:00
cd "$(dirname "$0")"
# bring down ghost instances.
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.
2022-11-14 01:26:51 +00:00
source "$RESPOSITORY_PATH/reset_env.sh"
2022-09-28 17:59:01 +00:00
source "$SITE_PATH/site_definition"
2022-11-14 01:26:51 +00:00
source "$RESPOSITORY_PATH/domain_env.sh"
2022-09-28 17:59:01 +00:00
### Stop all services.
2022-11-14 01:23:48 +00:00
for APP in ghost nextcloud gitea nostr; do
# backup each language for each app.
2022-09-28 17:59:01 +00:00
for LANGUAGE_CODE in ${SITE_LANGUAGE_CODES//,/ }; do
2022-10-19 17:15:38 +00:00
STACK_NAME="$DOMAIN_IDENTIFIER-$APP-$LANGUAGE_CODE"
2022-09-28 17:59:01 +00:00
if docker stack list --format "{{.Name}}" | grep -q "$STACK_NAME"; then
docker stack rm "$STACK_NAME"
sleep 2
fi
2022-10-08 16:44:46 +00:00
# these variable are used by both backup/restore scripts.
export APP="$APP"
2022-10-19 17:15:38 +00:00
export REMOTE_BACKUP_PATH="$REMOTE_HOME/backups/www/$APP/$DOMAIN_IDENTIFIER-$LANGUAGE_CODE"
2022-10-08 16:44:46 +00:00
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"
2022-10-08 16:44:46 +00:00
# ensure our local backup path exists.
if [ ! -d "$LOCAL_BACKUP_PATH" ]; then
mkdir -p "$LOCAL_BACKUP_PATH"
fi
if [ "$RESTORE_WWW" = true ]; then
./restore_path.sh
2022-10-10 00:35:02 +00:00
#ssh "$PRIMARY_WWW_FQDN" sudo chown ubuntu:ubuntu "$REMOTE_HOME/$APP"
else
2022-10-08 16:44:46 +00:00
# if we're not restoring, then we may or may not back up.
./backup_path.sh
fi
2022-09-28 17:59:01 +00:00
done
done
done
2022-12-25 17:59:02 +00:00
if [ "$RESTART_FRONT_END" = true ]; then
# remove the nginx stack
if docker stack list --format "{{.Name}}" | grep -q reverse-proxy; then
sleep 2
2022-11-05 23:50:59 +00:00
2022-12-25 17:59:02 +00:00
docker stack rm reverse-proxy
2022-09-28 17:59:01 +00:00
2022-12-25 17:59:02 +00:00
# wait for all docker containers to stop.
# TODO see if there's a way to check for this.
sleep 15
fi
2022-09-28 17:59:01 +00:00
2022-12-25 17:59:02 +00:00
# generate the certs and grab a backup
if [ "$RUN_CERT_RENEWAL" = true ]; then
./generate_certs.sh
fi
2022-11-14 01:26:51 +00:00
2022-12-25 17:59:02 +00:00
# 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
2022-09-28 17:59:01 +00:00
fi