Remove iteration over PROJECTS.
This commit is contained in:
parent
d786227a5f
commit
a4301c0a1c
@ -31,25 +31,7 @@ done
|
|||||||
|
|
||||||
. ./remote_env.sh
|
. ./remote_env.sh
|
||||||
|
|
||||||
for PROJECT_CHAIN in ${DEPLOYMENT_STRING//,/ }; do
|
. ./project_env.sh
|
||||||
NO_PARENS="${PROJECT_CHAIN:1:${#PROJECT_CHAIN}-2}"
|
|
||||||
PROJECT_PREFIX=$(echo "$NO_PARENS" | cut -d'|' -f1)
|
|
||||||
BITCOIN_CHAIN=$(echo "$NO_PARENS" | cut -d'|' -f2)
|
|
||||||
|
|
||||||
PROJECT_NAME="$PROJECT_PREFIX-$BITCOIN_CHAIN"
|
|
||||||
PROJECT_PATH="$PROJECTS_DIR/$PROJECT_NAME"
|
|
||||||
|
|
||||||
# if the user sets USER_TARGET_PROJECT, let's ensure the project exists.
|
|
||||||
if [ -n "$USER_TARGET_PROJECT" ]; then
|
|
||||||
if [ "$PROJECT_NAME" != "$USER_TARGET_PROJECT" ]; then
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
export PROJECT_NAME="$PROJECT_NAME"
|
|
||||||
export PROJECT_PATH="$PROJECT_PATH"
|
|
||||||
|
|
||||||
. ./project_env.sh
|
|
||||||
|
|
||||||
if ! lxc info | grep "project:" | grep -q "$PROJECT_NAME"; then
|
if ! lxc info | grep "project:" | grep -q "$PROJECT_NAME"; then
|
||||||
if lxc project list | grep -q "$PROJECT_NAME"; then
|
if lxc project list | grep -q "$PROJECT_NAME"; then
|
||||||
@ -90,22 +72,13 @@ for PROJECT_CHAIN in ${DEPLOYMENT_STRING//,/ }; do
|
|||||||
|
|
||||||
done
|
done
|
||||||
|
|
||||||
if lxc network list -q | grep -q ss-ovn; then
|
if lxc network list -q | grep -q ss-ovn; then
|
||||||
lxc network delete ss-ovn
|
lxc network delete ss-ovn
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! lxc info | grep "project:" | grep -q default; then
|
# delete the base image so it can be created.
|
||||||
lxc project switch default
|
if lxc list | grep -q "$BASE_IMAGE_VM_NAME"; then
|
||||||
fi
|
lxc delete -f "$BASE_IMAGE_VM_NAME" --project default
|
||||||
|
|
||||||
if lxc project list | grep -q "$PROJECT_NAME"; then
|
|
||||||
lxc project delete "$PROJECT_NAME"
|
|
||||||
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"
|
|
||||||
# remove the ssh known endpoint else we get warnings.
|
# remove the ssh known endpoint else we get warnings.
|
||||||
ssh-keygen -f "$SSH_HOME/known_hosts" -R "$LXD_NAME"
|
ssh-keygen -f "$SSH_HOME/known_hosts" -R "$BASE_IMAGE_VM_NAME"
|
||||||
fi
|
fi
|
||||||
done
|
|
||||||
|
@ -7,7 +7,6 @@ cd "$(dirname "$0")"
|
|||||||
|
|
||||||
. ./remote_env.sh
|
. ./remote_env.sh
|
||||||
|
|
||||||
|
|
||||||
echo "Global Settings:"
|
echo "Global Settings:"
|
||||||
|
|
||||||
lxc image list
|
lxc image list
|
||||||
@ -17,29 +16,22 @@ lxc storage volume list ss-base
|
|||||||
echo
|
echo
|
||||||
echo
|
echo
|
||||||
|
|
||||||
for PROJECT_CHAIN in ${DEPLOYMENT_STRING//,/ }; do
|
export PROJECT_NAME="$(lxc info | grep "project:" | awk '{print $2}')"
|
||||||
NO_PARENS="${PROJECT_CHAIN:1:${#PROJECT_CHAIN}-2}"
|
export PROJECT_PATH="$PROJECTS_PATH/$PROJECT_NAME"
|
||||||
PROJECT_PREFIX=$(echo "$NO_PARENS" | cut -d'|' -f1)
|
|
||||||
BITCOIN_CHAIN=$(echo "$NO_PARENS" | cut -d'|' -f2)
|
|
||||||
PROJECT_NAME="$PROJECT_PREFIX-$BITCOIN_CHAIN"
|
|
||||||
|
|
||||||
echo
|
|
||||||
echo
|
|
||||||
echo "Project: $PROJECT_NAME"
|
|
||||||
echo "----------------------------------------------------------"
|
|
||||||
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
|
|
||||||
|
|
||||||
echo " Networks:"
|
|
||||||
lxc network list
|
echo
|
||||||
echo
|
echo
|
||||||
echo " Profiles:"
|
echo "Project: $PROJECT_NAME"
|
||||||
lxc profile list
|
echo "----------------------------------------------------------"
|
||||||
echo
|
|
||||||
echo " Instances (VMs):"
|
echo " Networks:"
|
||||||
lxc list
|
lxc network list
|
||||||
echo "----------------------------------------------------------"
|
echo
|
||||||
done
|
echo " Profiles:"
|
||||||
|
lxc profile list
|
||||||
|
echo
|
||||||
|
echo " Instances (VMs):"
|
||||||
|
lxc list
|
||||||
|
echo "----------------------------------------------------------"
|
||||||
|
@ -22,59 +22,15 @@ if [ "$RESPONSE" != "y" ]; then
|
|||||||
exit 0
|
exit 0
|
||||||
fi
|
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
|
. ../defaults.sh
|
||||||
|
|
||||||
. ./remote_env.sh
|
. ./remote_env.sh
|
||||||
|
|
||||||
for PROJECT_CHAIN in ${DEPLOYMENT_STRING//,/ }; do
|
. ./project_env.sh
|
||||||
NO_PARENS="${PROJECT_CHAIN:1:${#PROJECT_CHAIN}-2}"
|
|
||||||
PROJECT_PREFIX=$(echo "$NO_PARENS" | cut -d'|' -f1)
|
|
||||||
BITCOIN_CHAIN=$(echo "$NO_PARENS" | cut -d'|' -f2)
|
|
||||||
export PROJECT_PREFIX="$PROJECT_PREFIX"
|
|
||||||
export BITCOIN_CHAIN="$BITCOIN_CHAIN"
|
|
||||||
|
|
||||||
PROJECT_NAME="$PROJECT_PREFIX-$BITCOIN_CHAIN"
|
# Check to see if any of the VMs actually don't exist.
|
||||||
PROJECT_PATH="$PROJECTS_DIR/$PROJECT_NAME"
|
# (we only migrate instantiated vms)
|
||||||
|
for VM in www btcpayserver; do
|
||||||
# if the user sets USER_TARGET_PROJECT, let's ensure the project exists.
|
|
||||||
if [ -n "$USER_TARGET_PROJECT" ]; then
|
|
||||||
if ! lxc project list | grep -q "$USER_TARGET_PROJECT"; then
|
|
||||||
echo "ERROR: the project does not exist! Nothing to update."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$PROJECT_NAME" != "$USER_TARGET_PROJECT" ]; then
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
export PROJECT_NAME="$PROJECT_NAME"
|
|
||||||
export PROJECT_PATH="$PROJECT_PATH"
|
|
||||||
|
|
||||||
. ./project_env.sh
|
|
||||||
|
|
||||||
# Check to see if any of the VMs actually don't exist.
|
|
||||||
# (we only migrate instantiated vms)
|
|
||||||
for VM in www btcpayserver; do
|
|
||||||
LXD_NAME="$VM-${DOMAIN_NAME//./-}"
|
LXD_NAME="$VM-${DOMAIN_NAME//./-}"
|
||||||
|
|
||||||
# if the VM doesn't exist, the we emit an error message and hard quit.
|
# if the VM doesn't exist, the we emit an error message and hard quit.
|
||||||
@ -82,48 +38,46 @@ for PROJECT_CHAIN in ${DEPLOYMENT_STRING//,/ }; do
|
|||||||
echo "ERROR: there is no VM named '$LXD_NAME'. You probably need to run ss-deploy again."
|
echo "ERROR: there is no VM named '$LXD_NAME'. You probably need to run ss-deploy again."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
done
|
|
||||||
|
|
||||||
BTCPAY_RESTORE_ARCHIVE_PATH="$SITES_PATH/$PRIMARY_DOMAIN/backups/btcpayserver/$(date +%s).tar.gz"
|
|
||||||
echo "INFO: The BTCPAY_RESTORE_ARCHIVE_PATH for this migration will be: $BTCPAY_RESTORE_ARCHIVE_PATH"
|
|
||||||
|
|
||||||
# first we run ss-deploy --stop
|
|
||||||
# this grabs a backup of all data (backups are on by default) and saves them to the management machine
|
|
||||||
# the --stop flag ensures that services do NOT come back online.
|
|
||||||
# by default, we grab a backup.
|
|
||||||
|
|
||||||
# first, let's grab the GIT commit from the remote machine.
|
|
||||||
export DOMAIN_NAME="$PRIMARY_DOMAIN"
|
|
||||||
export SITE_PATH="$SITES_PATH/$PRIMARY_DOMAIN"
|
|
||||||
|
|
||||||
# source the site path so we know what features it has.
|
|
||||||
source ../defaults.sh
|
|
||||||
source "$SITE_PATH/site.conf"
|
|
||||||
source ./project/domain_env.sh
|
|
||||||
|
|
||||||
# now we want to switch the git HEAD of the project subdirectory to the
|
|
||||||
# version of code that was last used
|
|
||||||
GIT_COMMIT_ON_REMOTE_HOST="$(ssh ubuntu@$BTCPAY_FQDN cat /home/ubuntu/.ss-githead)"
|
|
||||||
cd project/
|
|
||||||
echo "INFO: switch the 'project' repo to commit prior commit '$GIT_COMMIT_ON_REMOTE_HOST'"
|
|
||||||
echo " This allows Sovereign Stack to can grab a backup using the version of the code"
|
|
||||||
echo " that was used when the deployment was created."
|
|
||||||
git checkout "$GIT_COMMIT_ON_REMOTE_HOST"
|
|
||||||
cd -
|
|
||||||
|
|
||||||
# run deploy which backups up everything, but doesnt restart any services.
|
|
||||||
bash -c "./project/deploy.sh --project=$PROJECT_NAME --stop --no-cert-renew --backup-archive-path=$BTCPAY_RESTORE_ARCHIVE_PATH"
|
|
||||||
|
|
||||||
# call the destroy script. If user proceed, then user data is DESTROYED!
|
|
||||||
bash -c "./destroy.sh --project=$PROJECT_NAME"
|
|
||||||
|
|
||||||
cd project/
|
|
||||||
echo "INFO: switching the 'project' repo back to the most recent commit '$TARGET_PROJECT_GIT_COMMIT'"
|
|
||||||
echo " That way new deployments will be instantiated using the latest codebase."
|
|
||||||
git checkout "$TARGET_PROJECT_GIT_COMMIT"
|
|
||||||
cd -
|
|
||||||
|
|
||||||
# Then we can run a restore operation and specify the backup archive at the CLI.
|
|
||||||
bash -c "./project/deploy.sh --project=$PROJECT_NAME -y --restore-www --restore-btcpay --backup-archive-path=$BTCPAY_RESTORE_ARCHIVE_PATH"
|
|
||||||
|
|
||||||
done
|
done
|
||||||
|
|
||||||
|
BTCPAY_RESTORE_ARCHIVE_PATH="$SITES_PATH/$PRIMARY_DOMAIN/backups/btcpayserver/$(date +%s).tar.gz"
|
||||||
|
echo "INFO: The BTCPAY_RESTORE_ARCHIVE_PATH for this migration will be: $BTCPAY_RESTORE_ARCHIVE_PATH"
|
||||||
|
|
||||||
|
# first we run ss-deploy --stop
|
||||||
|
# this grabs a backup of all data (backups are on by default) and saves them to the management machine
|
||||||
|
# the --stop flag ensures that services do NOT come back online.
|
||||||
|
# by default, we grab a backup.
|
||||||
|
|
||||||
|
# first, let's grab the GIT commit from the remote machine.
|
||||||
|
export DOMAIN_NAME="$PRIMARY_DOMAIN"
|
||||||
|
export SITE_PATH="$SITES_PATH/$PRIMARY_DOMAIN"
|
||||||
|
|
||||||
|
# source the site path so we know what features it has.
|
||||||
|
source ../defaults.sh
|
||||||
|
source "$SITE_PATH/site.conf"
|
||||||
|
source ./project/domain_env.sh
|
||||||
|
|
||||||
|
# now we want to switch the git HEAD of the project subdirectory to the
|
||||||
|
# version of code that was last used
|
||||||
|
GIT_COMMIT_ON_REMOTE_HOST="$(ssh ubuntu@$BTCPAY_FQDN cat /home/ubuntu/.ss-githead)"
|
||||||
|
cd project/
|
||||||
|
echo "INFO: switch the 'project' repo to commit prior commit '$GIT_COMMIT_ON_REMOTE_HOST'"
|
||||||
|
echo " This allows Sovereign Stack to can grab a backup using the version of the code"
|
||||||
|
echo " that was used when the deployment was created."
|
||||||
|
git checkout "$GIT_COMMIT_ON_REMOTE_HOST"
|
||||||
|
cd -
|
||||||
|
|
||||||
|
# run deploy which backups up everything, but doesnt restart any services.
|
||||||
|
bash -c "./project/deploy.sh --stop --no-cert-renew --backup-archive-path=$BTCPAY_RESTORE_ARCHIVE_PATH"
|
||||||
|
|
||||||
|
# call the destroy script. This brings down the existing deployment. Does NOT destroy docker data.
|
||||||
|
bash -c "./destroy.sh"
|
||||||
|
|
||||||
|
cd project/
|
||||||
|
echo "INFO: switching the 'project' repo back to the most recent commit '$TARGET_PROJECT_GIT_COMMIT'"
|
||||||
|
echo " That way new deployments will be instantiated using the latest codebase."
|
||||||
|
git checkout "$TARGET_PROJECT_GIT_COMMIT"
|
||||||
|
cd -
|
||||||
|
|
||||||
|
# Then we can run a restore operation and specify the backup archive at the CLI.
|
||||||
|
bash -c "./project/deploy.sh -y --restore-www --restore-btcpay --backup-archive-path=$BTCPAY_RESTORE_ARCHIVE_PATH"
|
||||||
|
Loading…
Reference in New Issue
Block a user