1
1

Compare commits

..

No commits in common. "be69d5774d65b7807ff5843f8ec44e44dfae7bc0" and "441eff3f26559b467d8dddefff97bdd5c588c2fc" have entirely different histories.

14 changed files with 321 additions and 378 deletions

View File

@ -4,7 +4,7 @@ set -e
export DEPLOY_GHOST=true
export DEPLOY_CLAMS=false
export DEPLOY_NOSTR=false
export DEPLOY_NEXTCLOUD=false
export DEPLOY_GITEA=false
@ -71,13 +71,13 @@ export GITEA_DB_IMAGE="$DEFAULT_DB_IMAGE"
export NOSTR_RELAY_IMAGE="scsibug/nostr-rs-relay"
export WWW_SERVER_MAC_A DDRESS=
export WWW_SERVER_MAC_ADDRESS=
export BTCPAYSERVER_MAC_ADDRESS=
export SS_ROOT_PATH="$HOME/ss"
export SS_ROOT_PATH="$HOME/.ss"
export REMOTES_PATH="$SS_ROOT_PATH/remotes"
export PROJECTS_PATH="$SS_ROOT_PATH/projects"
export REMOTES_DIR="$SS_ROOT_PATH/remotes"
export PROJECTS_DIR="$SS_ROOT_PATH/projects"
export SITES_PATH="$SS_ROOT_PATH/sites"
# mount into ss-mgmt/home/ubuntu/snap/lxd/common/config
@ -96,29 +96,19 @@ export OTHER_SITES_LIST=
export BTCPAY_ALT_NAMES=
export BITCOIN_CHAIN=regtest
export REMOTE_HOME="/home/ubuntu"
export REMOTE_DATA_PATH="$REMOTE_HOME/ss-data"
export REMOTE_DATA_PATH_LETSENCRYPT="$REMOTE_DATA_PATH/letsencrypt"
export REMOTE_BACKUP_PATH="$REMOTE_HOME/backups"
export BTCPAY_SERVER_APPPATH="$REMOTE_DATA_PATH/btcpayserver-docker"
# this space is for OS, docker images, etc
# values here are fine for regtest generally. Later scripts adjust
# these values based on testnet/mainnet
export WWW_SSDATA_DISK_SIZE_GB=20
export WWW_BACKUP_DISK_SIZE_GB=50
export WWW_DOCKER_DISK_SIZE_GB=30
export BTCPAYSERVER_SSDATA_DISK_SIZE_GB=20
export BTCPAYSERVER_BACKUP_DISK_SIZE_GB=5
export BTCPAYSERVER_DOCKER_DISK_SIZE_GB=30
export BTCPAY_SERVER_APPPATH="$REMOTE_HOME/btcpayserver-docker"
export REMOTE_CERT_BASE_DIR="$REMOTE_HOME/.certs"
# this space is for OS, docker images, etc. DOES NOT INCLUDE USER DATA.
export ROOT_DISK_SIZE_GB=20
export REGISTRY_URL="https://index.docker.io/v1"
export PRIMARY_DOMAIN=
# this is the git commit of the project/ sub git repo.
# used in the migration script to switch into past for backup
# then back to present (TARGET_PROJECT_GIT_COMMIT) for restore.
export TARGET_PROJECT_GIT_COMMIT=f05daa9bfb11242eab920fdc4dd490d9bfdd6fbb
export TARGET_PROJECT_GIT_COMMIT=7a710d09162f98fa38e4c60fa00c87c8bcbeb5e9
#
export TESTNET_BLOCK_HASH=00000000d8277ba1ca66b40b3e3476629e6f0f97c5b8cfaeabfe402e55db223a

102
deployment/destroy.sh Executable file
View File

@ -0,0 +1,102 @@
#!/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
echo "WARNING: This will DESTROY any existing VMs!"
RESPONSE=
read -r -p "Are you sure you want to continue (y/n): ": RESPONSE
if [ "$RESPONSE" != "y" ]; then
echo "STOPPING."
exit 0
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
for PROJECT_CHAIN in ${DEPLOYMENT_STRING//,/ }; do
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 project list | grep -q "$PROJECT_NAME"; then
lxc project switch "$PROJECT_NAME"
fi
fi
for VM in www btcpayserver; do
LXD_NAME="$VM-${DOMAIN_NAME//./-}"
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
done
if lxc network list -q | grep -q ss-ovn; then
lxc network delete ss-ovn
fi
if ! lxc info | grep "project:" | grep -q default; then
lxc project switch default
fi
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.
ssh-keygen -f "$SSH_HOME/known_hosts" -R "$LXD_NAME"
fi
done

View File

@ -1,95 +0,0 @@
#!/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 --skip-$SKIP"
lxc stop "$LXD_NAME"
lxc delete "$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

View File

@ -2,13 +2,12 @@
You are in the Sovereign Stack Management Environment (SSME). From here, you can issue several commands:
ss-remote - Take a remote SSH endpoint under management of Sovereign Stack.
ss-reset - The opposite of ss-remote; de-provisions an existing remote.
ss-up - Instantiate a deployment to your active project according to your
ss-deploy - Deploys Sovereign Stack instances to your currenty remote according to your
various remote.conf, project.conf, and site.conf files.
ss-down - Reverses ss-up. Takes the active project down. Non-destructive of user data,
unless you provide the --destroy flag.
ss-update - This is just ss-down then ss-up.
ss-show - show the lxd resources associated with the current remote.
ss-update - brings an existing deployment up to the newest version of Sovereign Stack.
ss-destroy - Destroys the active deployment (WARNING: destructive).
ss-reset - The opposite of ss-remote; deprovisions on the current remote.
For more infomation about all these topics, consult the Sovereign Stack website starting with:

View File

@ -1,19 +1,8 @@
#!/bin/bash
set -eu
cd "$(dirname "$0")"
PROJECT_NAME="$(lxc info | grep "project:" | awk '{print $2}')"
export PROJECT_NAME="$PROJECT_NAME"
if [ "$PROJECT_NAME" = default ]; then
echo "ERROR: You are on the default project. Use 'lxc project list' and 'lxc project switch <project>'."
exit 1
fi
BITCOIN_CHAIN=$(echo "$PROJECT_NAME" | cut -d'-' -f2)
export PROJECT_PATH="$PROJECTS_PATH/$PROJECT_NAME"
export BITCOIN_CHAIN="$BITCOIN_CHAIN"
PROJECT_DEFINITION_PATH="$PROJECT_PATH/project.conf"
@ -38,13 +27,8 @@ fi
source "$PRIMARY_SITE_DEFINITION_PATH"
SHASUM_OF_PRIMARY_DOMAIN="$(echo -n "$PRIMARY_DOMAIN" | sha256sum | awk '{print $1;}' )"
export PRIMARY_DOMAIN_IDENTIFIER="${SHASUM_OF_PRIMARY_DOMAIN: -6}"
export WWW_SSDATA_DISK_SIZE_GB="$WWW_SSDATA_DISK_SIZE_GB"
export WWW_BACKUP_DISK_SIZE_GB="$WWW_BACKUP_DISK_SIZE_GB"
export WWW_DOCKER_DISK_SIZE_GB="$WWW_DOCKER_DISK_SIZE_GB"
export BTCPAYSERVER_SSDATA_DISK_SIZE_GB="$BTCPAYSERVER_SSDATA_DISK_SIZE_GB"
export BTCPAYSERVER_BACKUP_DISK_SIZE_GB="$BTCPAYSERVER_BACKUP_DISK_SIZE_GB"
export BTCPAYSERVER_DOCKER_DISK_SIZE_GB="$BTCPAYSERVER_DOCKER_DISK_SIZE_GB"
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

View File

@ -21,7 +21,7 @@ fi
#shellcheck disable=SC1091
source ../defaults.sh
export REMOTE_PATH="$REMOTES_PATH/$REMOTE_NAME"
export REMOTE_PATH="$REMOTES_DIR/$REMOTE_NAME"
REMOTE_DEFINITION="$REMOTE_PATH/remote.conf"
export REMOTE_DEFINITION="$REMOTE_DEFINITION"
@ -88,7 +88,6 @@ if ! lxc remote list | grep -q "$REMOTE_NAME"; then
ssh-copy-id -i "$HOME/.ssh/id_rsa.pub" "ubuntu@$FQDN"
if [ -z "$DISK_TO_USE" ]; then
if ! ssh "ubuntu@$FQDN" lxc storage list -q | grep -q ss-base; then
echo "INFO: It looks like the DISK_TO_USE has not been set. Enter it now."
echo ""
@ -97,7 +96,6 @@ if ! lxc remote list | grep -q "$REMOTE_NAME"; then
echo "Please enter the disk or partition that Sovereign Stack will use to store data: "
read -r DISK_TO_USE
fi
fi
else
echo "ERROR: the remote already exists! You need to go delete your lxd remote if you want to re-create your remote."
@ -131,14 +129,14 @@ if ! command -v lxc >/dev/null 2>&1; then
sleep 1
fi
if lxc network list --format csv -q --project default | grep -q lxdbr0; then
lxc network delete lxdbr0 --project default
if lxc network list --format csv | grep -q lxdbr0; then
lxc network delete lxdbr0
sleep 1
fi
if lxc network list --format csv -q project default | grep -q lxdbr1; then
lxc network delete lxdbr1 --project default
if lxc network list --format csv | grep -q lxdbr1; then
lxc network delete lxdbr1
sleep 1
fi
@ -152,7 +150,9 @@ if ! ssh "ubuntu@$FQDN" snap list | grep -q lxd; then
fi
# install OVN for the project-specific bridge networks
ssh -t "ubuntu@$FQDN" "sudo apt-get install -y ovn-host ovn-central && sudo ovs-vsctl set open_vswitch . external_ids:ovn-remote=unix:/var/run/ovn/ovnsb_db.sock external_ids:ovn-encap-type=geneve external_ids:ovn-encap-ip=127.0.0.1"
ssh -t "ubuntu@$FQDN" "sudo apt-get install -y ovn-host ovn-central"
ssh -t "ubuntu@$FQDN" "sudo ovs-vsctl set open_vswitch . external_ids:ovn-remote=unix:/var/run/ovn/ovnsb_db.sock external_ids:ovn-encap-type=geneve external_ids:ovn-encap-ip=127.0.0.1"
# if the user did not specify the interface, we just use whatever is used for the default route.
if [ -z "$DATA_PLANE_MACVLAN_INTERFACE" ]; then
@ -240,14 +240,14 @@ if ! lxc storage list --format csv | grep -q ss-base; then
lxc storage create ss-base zfs
fi
# # create the testnet/mainnet blocks/chainstate subvolumes.
# for CHAIN in mainnet testnet; do
# for DATA in blocks chainstate; do
# if ! lxc storage volume list ss-base | grep -q "$CHAIN-$DATA"; then
# lxc storage volume create ss-base "$CHAIN-$DATA" --type=filesystem
# fi
# done
# done
# create the testnet/mainnet blocks/chainstate subvolumes.
for CHAIN in mainnet testnet; do
for DATA in blocks chainstate; do
if ! lxc storage volume list ss-base | grep -q "$CHAIN-$DATA"; then
lxc storage volume create ss-base "$CHAIN-$DATA" --type=filesystem
fi
done
done
else
echo "WARNING! The host '$FQDN' appears to have Sovereign Stack worksloads already provisioned. Proceed with care."

View File

@ -1,6 +1,7 @@
#!/bin/bash
set -eu
cd "$(dirname "$0")"
CURRENT_REMOTE="$(lxc remote get-default)"
@ -25,7 +26,7 @@ if echo "$CURRENT_REMOTE" | grep -q "production"; then
fi
export REMOTE_PATH="$REMOTES_PATH/$CURRENT_REMOTE"
export REMOTE_PATH="$REMOTES_DIR/$CURRENT_REMOTE"
REMOTE_DEFINITION="$REMOTE_PATH/remote.conf"
export REMOTE_DEFINITION="$REMOTE_DEFINITION"
@ -37,50 +38,3 @@ if [ ! -f "$REMOTE_DEFINITION" ]; then
fi
source "$REMOTE_DEFINITION"
# ensure our projects are provisioned according to DEPLOYMENT_STRING
for PROJECT_CHAIN in ${DEPLOYMENT_STRING//,/ }; do
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"
# create the lxc project as specified by PROJECT_NAME
if ! lxc project list | grep -q "$PROJECT_NAME"; then
lxc project create "$PROJECT_NAME"
lxc project set "$PROJECT_NAME" features.networks=true features.images=false features.storage.volumes=true
lxc project switch "$PROJECT_NAME"
fi
# default values are already at regtest mode.
if [ "$BITCOIN_CHAIN" = testnet ]; then
WWW_SSDATA_DISK_SIZE_GB=30
WWW_BACKUP_DISK_SIZE_GB=30
WWW_DOCKER_DISK_SIZE_GB=50
BTCPAYSERVER_SSDATA_DISK_SIZE_GB=30
BTCPAYSERVER_BACKUP_DISK_SIZE_GB=30
BTCPAYSERVER_DOCKER_DISK_SIZE_GB=100
elif [ "$BITCOIN_CHAIN" = mainnet ]; then
WWW_SSDATA_DISK_SIZE_GB=40
WWW_BACKUP_DISK_SIZE_GB=40
WWW_DOCKER_DISK_SIZE_GB=1000
BTCPAYSERVER_SSDATA_DISK_SIZE_GB=30
BTCPAYSERVER_BACKUP_DISK_SIZE_GB=30
BTCPAYSERVER_DOCKER_DISK_SIZE_GB=500
fi
export WWW_SSDATA_DISK_SIZE_GB="$WWW_SSDATA_DISK_SIZE_GB"
export WWW_BACKUP_DISK_SIZE_GB="$WWW_BACKUP_DISK_SIZE_GB"
export WWW_DOCKER_DISK_SIZE_GB="$WWW_DOCKER_DISK_SIZE_GB"
export BTCPAYSERVER_SSDATA_DISK_SIZE_GB="$BTCPAYSERVER_SSDATA_DISK_SIZE_GB"
export BTCPAYSERVER_BACKUP_DISK_SIZE_GB="$BTCPAYSERVER_BACKUP_DISK_SIZE_GB"
export BTCPAYSERVER_DOCKER_DISK_SIZE_GB="$BTCPAYSERVER_DOCKER_DISK_SIZE_GB"
done

View File

@ -23,7 +23,7 @@ done
source ../defaults.sh
./down.sh
./destroy.sh
# these only get initialzed upon creation, so we MUST delete here so they get recreated.
if lxc profile list | grep -q "$BASE_IMAGE_VM_NAME"; then
@ -55,22 +55,22 @@ if [ "$PURGE_LXD" = true ]; then
lxc profile device remove default eth0
fi
if lxc network list --format csv -q --project default | grep -q lxdbr0; then
lxc network delete lxdbr0 --project default
if lxc network list --format csv | grep -q lxdbr0; then
lxc network delete lxdbr0
fi
if lxc network list --format csv -q --project default | grep -q lxdbr1; then
lxc network delete lxdbr1 --project default
if lxc network list --format csv | grep -q lxdbr1; then
lxc network delete lxdbr1
fi
# # create the testnet/mainnet blocks/chainstate subvolumes.
# for CHAIN in mainnet testnet; do
# for DATA in blocks chainstate; do
# if lxc storage volume list ss-base | grep -q "$CHAIN-$DATA"; then
# lxc storage volume delete ss-base "$CHAIN-$DATA"
# fi
# done
# done
# create the testnet/mainnet blocks/chainstate subvolumes.
for CHAIN in mainnet testnet; do
for DATA in blocks chainstate; do
if lxc storage volume list ss-base | grep -q "$CHAIN-$DATA"; then
lxc storage volume delete ss-base "$CHAIN-$DATA"
fi
done
done
if lxc storage list --format csv | grep -q ss-base; then
lxc storage delete ss-base

View File

@ -7,36 +7,39 @@ cd "$(dirname "$0")"
. ./remote_env.sh
echo "Global Settings:"
lxc image list
lxc storage list
echo
echo
PROJECT_NAME="$(lxc info | grep "project:" | awk '{print $2}')"
export export="$PROJECT_NAME"
export PROJECT_PATH="$PROJECTS_PATH/$PROJECT_NAME"
echo
echo
echo "Active project: $PROJECT_NAME"
echo "----------------------------------------------------------"
echo " Networks:"
lxc network list
echo
echo " Storage Volumes:"
lxc storage volume list ss-base
echo
echo " Profiles:"
lxc profile list
echo
echo " Instances (VMs):"
lxc list
for PROJECT_CHAIN in ${DEPLOYMENT_STRING//,/ }; do
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"
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 " Profiles:"
lxc profile list
echo
echo " Instances (VMs):"
lxc list
echo "----------------------------------------------------------"
done

View File

@ -22,15 +22,59 @@ if [ "$RESPONSE" != "y" ]; then
exit 0
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
for PROJECT_CHAIN in ${DEPLOYMENT_STRING//,/ }; do
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"
# Check to see if any of the VMs actually don't exist.
# (we only migrate instantiated vms)
for VM in www btcpayserver; do
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 ! 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
exit
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//./-}"
# if the VM doesn't exist, the we emit an error message and hard quit.
@ -38,55 +82,48 @@ for VM in www btcpayserver; do
echo "ERROR: there is no VM named '$LXD_NAME'. You probably need to run ss-deploy again."
exit 1
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
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 --backup-archive-path=$BTCPAY_RESTORE_ARCHIVE_PATH --backup-www --backup-btcpayserver"
# call the down script (be default it is non-destructuve of user data.)
./down.sh
# next we switch back to the current version of Sovereign Stack scripts for bringin up the new version.
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 -
# TODO we can do some additional logic here. FOr example if the user wants to provide a source/target project/remote,
# we can backup the source remote+project and restore it to the target remote+project. This will facilitate cross-device migrations
# However, if the source and target project/remote are the same, we don't really
# need to do any restorations (or backups for that matter, though we still grab one);
# we simply mount the existing data. That's the more common case where the user is simply upgrading the system in-place.
./project/deploy.sh

View File

@ -1,9 +1,9 @@
#!/bin/bash
set -eu
set -exu
cd "$(dirname "$0")"
# https://www.sovereign-stack.org/install/
# see https://www.sovereign-stack.org/management/
# this script is not meant to be executed from the SSME; Let's let's check and abort if so.
if [ "$(hostname)" = ss-mgmt ]; then
@ -19,6 +19,13 @@ fi
DISK="rpool/lxd"
export DISK="$DISK"
# let's check to ensure the management machine is on the Baseline ubuntu
# TODO maybe remove this check; this theoretically should work on anything that support bash and lxd?
if ! lsb_release -d | grep -q "Ubuntu 22.04"; then
echo "ERROR: Your machine is not running the Ubuntu 22.04 LTS baseline OS on your management machine."
exit 1
fi
# install lxd snap and initialize it
if ! snap list | grep -q lxd; then
sudo snap install lxd --channel=latest/candidate
@ -79,68 +86,48 @@ fi
# if the ss-mgmt doesn't exist, create it.
SSH_PUBKEY_PATH="$HOME/.ssh/id_rsa.pub"
FROM_BUILT_IMAGE=false
if ! lxc list --format csv | grep -q ss-mgmt; then
# TODO check to see if there's an existing ss-mgmt image to spawn from, otherwise do this.
if lxc image list | grep -q ss-mgmt; then
FROM_BUILT_IMAGE=true
lxc init ss-mgmt ss-mgmt --vm -c limits.cpu=4 -c limits.memory=4GiB --profile=default
else
lxc init "images:$BASE_LXC_IMAGE" ss-mgmt --vm -c limits.cpu=4 -c limits.memory=4GiB --profile=default
# mount the pre-verified sovereign stack git repo into the new vm
lxc config device add ss-mgmt ss-code disk source="$(pwd)" path=/home/ubuntu/sovereign-stack
# create the ~/.ss path and mount it into the vm.
mkdir -p "$SS_ROOT_PATH"
lxc config device add ss-mgmt ss-root disk source="$SS_ROOT_PATH" path=/home/ubuntu/.ss
# if a ~/.bitcoin/testnet3/blocks direrectory exists, mount it in.
BITCOIN_DIR="$HOME/.bitcoin"
REMOTE_BITCOIN_CACHE_PATH="/home/ubuntu/.ss/cache/bitcoin"
BITCOIN_TESTNET_BLOCKS_PATH="$BITCOIN_DIR/testnet3/blocks"
if [ -d "$BITCOIN_TESTNET_BLOCKS_PATH" ]; then
lxc config device add ss-mgmt ss-testnet-blocks disk source="$BITCOIN_TESTNET_BLOCKS_PATH" path=$REMOTE_BITCOIN_CACHE_PATH/testnet/blocks
fi
fi
# if a ~/.bitcoin/testnet3/blocks direrectory exists, mount it in.
BITCOIN_TESTNET_CHAINSTATE_PATH="$BITCOIN_DIR/testnet3/chainstate"
if [ -d "$BITCOIN_TESTNET_CHAINSTATE_PATH" ]; then
lxc config device add ss-mgmt ss-testnet-chainstate disk source="$BITCOIN_TESTNET_CHAINSTATE_PATH" path=$REMOTE_BITCOIN_CACHE_PATH/testnet/chainstate
fi
# mount the pre-verified sovereign stack git repo into the new vm
if ! lxc config device show ss-mgmt | grep -q ss-code; then
lxc config device add ss-mgmt ss-code disk source="$(pwd)" path=/home/ubuntu/sovereign-stack
fi
# if a ~/.bitcoin/blocks dir exists, mount it in.
BITCOIN_MAINNET_BLOCKS_PATH="$BITCOIN_DIR/blocks"
if [ -d "$BITCOIN_MAINNET_BLOCKS_PATH" ]; then
lxc config device add ss-mgmt ss-mainnet-blocks disk source="$BITCOIN_MAINNET_BLOCKS_PATH" path=$REMOTE_BITCOIN_CACHE_PATH/mainnet/blocks
else
echo "INFO: the blocks directory was not found for mainnet. It will NOT be mounted into ss-mgmt."
fi
# create the ~/ss path and mount it into the vm.
mkdir -p "$SS_ROOT_PATH"
# if a ~/.bitcoin/testnet3/blocks direrectory exists, mount it in.
BITCOIN_MAINNET_CHAINSTATE_PATH="$BITCOIN_DIR/chainstate"
if [ -d "$BITCOIN_MAINNET_CHAINSTATE_PATH" ]; then
lxc config device add ss-mgmt ss-mainnet-chainstate disk source="$BITCOIN_MAINNET_CHAINSTATE_PATH" path=$REMOTE_BITCOIN_CACHE_PATH/mainnet/chainstate
else
echo "INFO: the chainstate directory was not found for mainnet. It will NOT be mounted into ss-mgmt."
fi
if ! lxc config device show ss-mgmt | grep -q ss-root; then
lxc config device add ss-mgmt ss-root disk source="$SS_ROOT_PATH" path=/home/ubuntu/ss
fi
# # if a ~/.bitcoin/testnet3/blocks direrectory exists, mount it in.
# BITCOIN_DIR="$HOME/.bitcoin"
# REMOTE_BITCOIN_CACHE_PATH="/home/ubuntu/ss/cache/bitcoin"
# BITCOIN_TESTNET_BLOCKS_PATH="$BITCOIN_DIR/testnet3/blocks"
# if [ -d "$BITCOIN_TESTNET_BLOCKS_PATH" ]; then
# if ! lxc config device show ss-mgmt | grep -q ss-testnet-blocks; then
# lxc config device add ss-mgmt ss-testnet-blocks disk source="$BITCOIN_TESTNET_BLOCKS_PATH" path=$REMOTE_BITCOIN_CACHE_PATH/testnet/blocks
# fi
# fi
# # if a ~/.bitcoin/testnet3/blocks direrectory exists, mount it in.
# BITCOIN_TESTNET_CHAINSTATE_PATH="$BITCOIN_DIR/testnet3/chainstate"
# if [ -d "$BITCOIN_TESTNET_CHAINSTATE_PATH" ]; then
# if ! lxc config device show ss-mgmt | grep -q ss-testnet-chainstate; then
# lxc config device add ss-mgmt ss-testnet-chainstate disk source="$BITCOIN_TESTNET_CHAINSTATE_PATH" path=$REMOTE_BITCOIN_CACHE_PATH/testnet/chainstate
# fi
# fi
# # if a ~/.bitcoin/blocks dir exists, mount it in.
# BITCOIN_MAINNET_BLOCKS_PATH="$BITCOIN_DIR/blocks"
# if [ -d "$BITCOIN_MAINNET_BLOCKS_PATH" ]; then
# if ! lxc config device show ss-mgmt | grep -q ss-mainnet-blocks; then
# lxc config device add ss-mgmt ss-mainnet-blocks disk source="$BITCOIN_MAINNET_BLOCKS_PATH" path=$REMOTE_BITCOIN_CACHE_PATH/mainnet/blocks
# fi
# fi
# # if a ~/.bitcoin/testnet3/blocks direrectory exists, mount it in.
# BITCOIN_MAINNET_CHAINSTATE_PATH="$BITCOIN_DIR/chainstate"
# if [ -d "$BITCOIN_MAINNET_CHAINSTATE_PATH" ]; then
# if ! lxc config device show ss-mgmt | grep -q ss-mainnet-blocks; then
# lxc config device add ss-mgmt ss-mainnet-chainstate disk source="$BITCOIN_MAINNET_CHAINSTATE_PATH" path=$REMOTE_BITCOIN_CACHE_PATH/mainnet/chainstate
# fi
# fi
# mount the ssh directory in there.
if [ -f "$SSH_PUBKEY_PATH" ]; then
if ! lxc config device show ss-mgmt | grep -q ss-ssh; then
# mount the ssh directory in there.
if [ -f "$SSH_PUBKEY_PATH" ]; then
lxc config device add ss-mgmt ss-ssh disk source="$HOME/.ssh" path=/home/ubuntu/.ssh
fi
fi
@ -189,25 +176,15 @@ ssh-keyscan -H -t ecdsa "$IP_V4_ADDRESS" >> "$SSH_HOME/known_hosts"
ssh "ubuntu@$IP_V4_ADDRESS" sudo chown -R ubuntu:ubuntu /home/ubuntu
ssh "ubuntu@$IP_V4_ADDRESS" /home/ubuntu/sovereign-stack/management/provision.sh
if [ "$FROM_BUILT_IMAGE" = false ]; then
ssh "ubuntu@$IP_V4_ADDRESS" /home/ubuntu/sovereign-stack/management/provision.sh
lxc stop ss-mgmt
if ! lxc image list | grep -q "ss-mgmt"; then
lxc publish ss-mgmt --alias=ss-mgmt
fi
lxc start ss-mgmt
fi
#lxc restart ss-mgmt
if [ "$ADDED_COMMAND" = true ]; then
echo "NOTICE! You need to run 'source ~/.bashrc' before continuing. After that, type 'ss-manage' to enter your management environment."
fi
. ./defaults.sh
# As part of the install script, we pull down any other sovereign-stack git repos
PROJECTS_SCRIPTS_REPO_URL="https://git.sovereign-stack.org/ss/project"
PROJECTS_SCRIPTS_PATH="$(pwd)/deployment/project"

View File

@ -1,16 +1,8 @@
#!/bin/bash
# https://www.sovereign-stack.org/ss-manage/
set -eu
cd "$(dirname "$0")"
# check to ensure dependencies are met.
if ! command -v lxc >/dev/null 2>&1; then
echo "This script requires 'lxd/lxc' to be installed. Please run 'install.sh'."
exit 1
fi
if ! lxc remote get-default | grep -q "local"; then
lxc remote switch "local"
fi

View File

@ -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-down='/home/ubuntu/sovereign-stack/deployment/down.sh $@'
alias ss-destroy='/home/ubuntu/sovereign-stack/deployment/destroy.sh $@'
alias ss-help='cat /home/ubuntu/sovereign-stack/deployment/help.txt'
alias ll='ls -lah'

View File

@ -1,6 +1,6 @@
#!/bin/bash
set -eu
set -exu
PURGE_LXD=false
@ -57,7 +57,7 @@ if [ "$PURGE_LXD" = true ]; then
lxc profile device remove default enp5s0
fi
if lxc network list --project default | grep -q lxdbr0; then
if lxc network list | grep -q lxdbr0; then
lxc network delete lxdbr0
fi