From 33a855e8014670a853c118c812a2f7a2fd21f678 Mon Sep 17 00:00:00 2001 From: Derek Smith Date: Tue, 4 Apr 2023 11:27:27 -0400 Subject: [PATCH] Rename ss-destroy to ss-down --- deployment/destroy.sh | 84 ------------------------------------ deployment/down.sh | 94 +++++++++++++++++++++++++++++++++++++++++ management/bash_aliases | 2 +- 3 files changed, 95 insertions(+), 85 deletions(-) delete mode 100755 deployment/destroy.sh create mode 100755 deployment/down.sh diff --git a/deployment/destroy.sh b/deployment/destroy.sh deleted file mode 100755 index 7af25a6..0000000 --- a/deployment/destroy.sh +++ /dev/null @@ -1,84 +0,0 @@ -#!/bin/bash - -set -e -cd "$(dirname "$0")" - -# this script destroys all resources in the current project. - -if lxc remote get-default | grep -q "local"; then - echo "ERROR: you are on the local lxc remote. Nothing to destroy" - exit 1 -fi - -USER_TARGET_PROJECT= - -# grab any modifications from the command line. -for i in "$@"; do - case $i in - --project=*) - USER_TARGET_PROJECT="${i#*=}" - shift - ;; - - *) - echo "Unexpected option: $1" - exit 1 - ;; - esac -done - -. ../defaults.sh - -. ./remote_env.sh - -. ./project_env.sh - - if ! lxc info | grep "project:" | grep -q "$PROJECT_NAME"; then - if lxc project list | grep -q "$PROJECT_NAME"; then - lxc project switch "$PROJECT_NAME" - fi - fi - - for VIRTUAL_MACHINE in www btcpayserver; do - LXD_NAME="$VIRTUAL_MACHINE-${PRIMARY_DOMAIN//./-}" - - if lxc list | grep -q "$LXD_NAME"; then - lxc delete -f "$LXD_NAME" - - # remove the ssh known endpoint else we get warnings. - ssh-keygen -f "$SSH_HOME/known_hosts" -R "$LXD_NAME" - fi - - if lxc profile list | grep -q "$LXD_NAME"; then - lxc profile delete "$LXD_NAME" - fi - - # destroy the docker volume - VM_ID=w - if [ "$VIRTUAL_MACHINE" = btcpayserver ]; then - VM_ID="b" - fi - - RESPONSE= - read -r -p "Do you want to delete the docker volume for '$LXD_NAME'?": RESPONSE - if [ "$RESPONSE" = "y" ]; then - VOLUME_NAME="$PRIMARY_DOMAIN_IDENTIFIER-$VM_ID" - if lxc storage volume list ss-base | grep -q "$VOLUME_NAME"; then - lxc storage volume delete ss-base "$VOLUME_NAME" - fi - else - echo "INFO: User DID NOT select 'y'. The storage volume will remain." - fi - - done - -if lxc network list -q | grep -q ss-ovn; then - lxc network delete ss-ovn -fi - -# delete the base image so it can be created. -if lxc list | grep -q "$BASE_IMAGE_VM_NAME"; then - lxc delete -f "$BASE_IMAGE_VM_NAME" --project default - # remove the ssh known endpoint else we get warnings. - ssh-keygen -f "$SSH_HOME/known_hosts" -R "$BASE_IMAGE_VM_NAME" -fi diff --git a/deployment/down.sh b/deployment/down.sh new file mode 100755 index 0000000..af7d72b --- /dev/null +++ b/deployment/down.sh @@ -0,0 +1,94 @@ +#!/bin/bash + +# https://www.sovereign-stack.org/ss-down/ + +set -exu +cd "$(dirname "$0")" + +if lxc remote get-default -q | grep -q "local"; then + echo "ERROR: you are on the local lxc remote. Nothing to take down" + exit 1 +fi + +KEEP_DOCKER_VOLUME=true + +# grab any modifications from the command line. +for i in "$@"; do + case $i in + --destroy) + KEEP_DOCKER_VOLUME=false + shift + ;; + *) + echo "Unexpected option: $1" + exit 1 + ;; + esac +done + +. ../defaults.sh + +. ./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 + + +SKIP=btcpayserver +for VIRTUAL_MACHINE in www btcpayserver; do + LXD_NAME="$VIRTUAL_MACHINE-${PRIMARY_DOMAIN//./-}" + + if lxc list | grep -q "$LXD_NAME"; then + bash -c "./project/deploy.sh --stop --no-cert-renew --skip-$SKIP" + + lxc delete -f "$LXD_NAME" + + # remove the ssh known endpoint else we get warnings. + ssh-keygen -f "$SSH_HOME/known_hosts" -R "$LXD_NAME" + fi + + if lxc profile list | grep -q "$LXD_NAME"; then + lxc profile delete "$LXD_NAME" + fi + + if [ "$KEEP_DOCKER_VOLUME" = false ]; then + # destroy the docker volume + VM_ID=w + if [ "$VIRTUAL_MACHINE" = btcpayserver ]; then + VM_ID="b" + fi + + # d for docker; b for backup; s for ss-data + for DATA in d b s; do + VOLUME_NAME="$PRIMARY_DOMAIN_IDENTIFIER-$VM_ID""$DATA" + if lxc storage volume list ss-base -q | grep -q "$VOLUME_NAME"; then + RESPONSE= + read -r -p "Are you sure you want to delete the '$VOLUME_NAME' volume intended for '$LXD_NAME'?": RESPONSE + + if [ "$RESPONSE" = "y" ]; then + lxc storage volume delete ss-base "$VOLUME_NAME" + fi + fi + done + fi + + SKIP=www +done + +if lxc network list -q | grep -q ss-ovn; then + lxc network delete ss-ovn +fi + +# delete the base image so it can be created. +if lxc list | grep -q "$BASE_IMAGE_VM_NAME"; then + lxc delete -f "$BASE_IMAGE_VM_NAME" --project default + # remove the ssh known endpoint else we get warnings. + ssh-keygen -f "$SSH_HOME/known_hosts" -R "$BASE_IMAGE_VM_NAME" +fi diff --git a/management/bash_aliases b/management/bash_aliases index b29b37a..e23bad1 100755 --- a/management/bash_aliases +++ b/management/bash_aliases @@ -5,7 +5,7 @@ alias ss-remote='/home/ubuntu/sovereign-stack/deployment/remote.sh $@' alias ss-show='/home/ubuntu/sovereign-stack/deployment/show.sh $@' alias ss-reset='/home/ubuntu/sovereign-stack/deployment/reset.sh $@' alias ss-update='/home/ubuntu/sovereign-stack/deployment/update.sh $@' -alias ss-destroy='/home/ubuntu/sovereign-stack/deployment/destroy.sh $@' +alias ss-down='/home/ubuntu/sovereign-stack/deployment/down.sh $@' alias ss-help='cat /home/ubuntu/sovereign-stack/deployment/help.txt' alias ll='ls -lah'