1
1
sovereign-stack/deployment/down.sh

117 lines
2.8 KiB
Bash
Raw Normal View History

2023-04-04 15:27:27 +00:00
#!/bin/bash
# https://www.sovereign-stack.org/ss-down/
2023-08-21 00:47:27 +00:00
set -exu
2023-04-04 15:27:27 +00:00
cd "$(dirname "$0")"
2023-09-22 23:46:07 +00:00
if incus remote get-default -q | grep -q "local"; then
echo "ERROR: you are on the local incus remote. Nothing to take down"
2023-04-04 15:27:27 +00:00
exit 1
fi
KEEP_DOCKER_VOLUME=true
2023-08-12 16:22:34 +00:00
OTHER_SITES_LIST=
2023-12-14 17:47:16 +00:00
SKIP_BTCPAY_SERVER=false
SKIP_WWW_SERVER=false
2023-09-06 02:01:57 +00:00
SKIP_LNPLAY_SERVER=false
2023-08-21 00:47:27 +00:00
BACKUP_WWW_APPS=true
2023-04-04 15:27:27 +00:00
# grab any modifications from the command line.
for i in "$@"; do
case $i in
2023-08-12 16:22:34 +00:00
--purge)
2023-04-04 15:27:27 +00:00
KEEP_DOCKER_VOLUME=false
shift
;;
2023-08-12 16:14:00 +00:00
--skip-btcpayserver)
2023-12-14 17:47:16 +00:00
SKIP_BTCPAY_SERVER=true
2023-08-12 16:14:00 +00:00
shift
;;
--skip-wwwserver)
2023-12-14 17:47:16 +00:00
SKIP_WWW_SERVER=true
2023-08-12 16:14:00 +00:00
shift
;;
2023-09-06 02:01:57 +00:00
--skip-lnplayserver)
SKIP_LNPLAY_SERVER=true
2023-08-12 16:14:00 +00:00
shift
;;
2023-04-04 15:27:27 +00:00
*)
echo "Unexpected option: $1"
exit 1
;;
esac
done
2023-08-12 16:14:00 +00:00
SERVERS=
2023-12-14 17:47:16 +00:00
if [ "$SKIP_BTCPAY_SERVER" = false ]; then
2023-08-12 16:14:00 +00:00
SERVERS="btcpayserver"
fi
2023-12-14 17:47:16 +00:00
if [ "$SKIP_WWW_SERVER" = false ]; then
2023-08-12 16:14:00 +00:00
SERVERS="www $SERVERS"
fi
2023-09-06 02:01:57 +00:00
if [ "$SKIP_LNPLAY_SERVER" = false ]; then
SERVERS="lnplayserver $SERVERS"
2023-08-12 16:14:00 +00:00
fi
2023-04-07 18:02:24 +00:00
. ./deployment_defaults.sh
2023-04-04 15:27:27 +00:00
. ./remote_env.sh
. ./project_env.sh
# let's bring down services on the remote deployment if necessary.
export DOMAIN_NAME="$PRIMARY_DOMAIN"
export SITE_PATH="$SITES_PATH/$PRIMARY_DOMAIN"
source "$SITE_PATH/site.conf"
source ./project/domain_env.sh
2023-08-12 16:21:15 +00:00
source ./domain_list.sh
for VIRTUAL_MACHINE in $SERVERS; do
2023-11-29 19:04:24 +00:00
INCUS_VM_NAME="$VIRTUAL_MACHINE-${PRIMARY_DOMAIN//./-}"
2023-04-04 15:27:27 +00:00
2023-11-29 19:04:24 +00:00
if incus list | grep -q "$INCUS_VM_NAME"; then
2023-08-12 16:21:15 +00:00
bash -c "./stop.sh --server=$VIRTUAL_MACHINE"
2023-04-04 15:27:27 +00:00
2023-11-29 19:04:24 +00:00
incus stop "$INCUS_VM_NAME"
2023-04-05 15:11:11 +00:00
2023-11-29 19:04:24 +00:00
incus delete "$INCUS_VM_NAME"
2023-04-04 15:27:27 +00:00
fi
2023-04-07 18:02:24 +00:00
# remove the ssh known endpoint else we get warnings.
ssh-keygen -f "$SSH_HOME/known_hosts" -R "$VIRTUAL_MACHINE.$PRIMARY_DOMAIN" | exit
2023-11-29 19:04:24 +00:00
if incus profile list | grep -q "$INCUS_VM_NAME"; then
incus profile delete "$INCUS_VM_NAME"
2023-04-04 15:27:27 +00:00
fi
if [ "$KEEP_DOCKER_VOLUME" = false ]; then
# d for docker; b for backup; s for ss-data
2023-12-12 20:09:07 +00:00
for DATA in docker backup ss-data; do
VOLUME_NAME="$VIRTUAL_MACHINE-$DATA"
2023-09-22 23:46:07 +00:00
if incus storage volume list ss-base -q | grep -q "$VOLUME_NAME"; then
2023-04-04 15:27:27 +00:00
RESPONSE=
2023-11-29 19:04:24 +00:00
read -r -p "Are you sure you want to delete the '$VOLUME_NAME' volume intended for '$INCUS_VM_NAME'?": RESPONSE
2023-04-04 15:27:27 +00:00
if [ "$RESPONSE" = "y" ]; then
2023-09-22 23:46:07 +00:00
incus storage volume delete ss-base "$VOLUME_NAME"
2023-04-04 15:27:27 +00:00
fi
fi
done
2023-08-12 16:22:34 +00:00
else
2023-08-12 16:14:00 +00:00
# we maintain the volumes
# TODO make a snapshot on all the zfs storage volumes.
echo "TODO: create snapshot of ZFS volumes and pull them to mgmt machine."
2023-04-04 15:27:27 +00:00
fi
done
2023-09-22 23:46:07 +00:00
if incus network list -q | grep -q ss-ovn; then
incus network delete ss-ovn
2023-08-21 00:47:27 +00:00
fi