1
1

Compare commits

...

24 Commits

Author SHA1 Message Date
be69d5774d
Update ss location. 2023-04-05 20:16:23 -04:00
e4a19010c6
Updates 2023-04-05 20:08:57 -04:00
9c0e29f772
Update comment. 2023-04-05 15:40:43 -04:00
54be0f6b3c
Update project ref. 2023-04-05 12:09:31 -04:00
bf5ff6903e
Fix cert renewal logic. 2023-04-05 12:00:39 -04:00
a3b29e129a
Make shutdown process less harsh. 2023-04-05 11:11:11 -04:00
6a0255a326
All other changes. 2023-04-04 16:25:58 -04:00
a1c50b083d
Comment all blockchain/chainstate stuff 2023-04-04 16:25:20 -04:00
0f65419d55
Make volumes project-specific. 2023-04-04 16:24:39 -04:00
cae11df6a5
Update project ref. 2023-04-04 11:44:56 -04:00
18bff0d2e9
Update target git commit. 2023-04-04 11:35:00 -04:00
425bfd8069
Leftovers. 2023-04-04 11:34:48 -04:00
b82813231c
Remote update. 2023-04-04 11:34:20 -04:00
f2b02e474d
Add dependency check. 2023-04-04 11:33:50 -04:00
5a54400831
Scope to correct project. 2023-04-04 11:32:54 -04:00
69ab9d0a42
Supporting stuff for volume mount work. 2023-04-04 11:31:24 -04:00
35afd1bbd4
Path updates. 2023-04-04 11:30:07 -04:00
a44ce22e00
Minor nostr updates. 2023-04-04 11:28:39 -04:00
33a855e801
Rename ss-destroy to ss-down 2023-04-04 11:27:27 -04:00
69161e726e
Improve install/uninstall.sh 2023-04-02 09:43:55 -04:00
622741ce06
Add/update variable names. 2023-04-02 09:42:55 -04:00
a4301c0a1c
Remove iteration over PROJECTS. 2023-04-02 09:41:42 -04:00
d786227a5f
undo 2023-03-30 11:10:42 -04:00
7d839e9724
Add removal of docker volume. 2023-03-30 11:08:34 -04:00
14 changed files with 376 additions and 319 deletions

View File

@ -4,7 +4,7 @@ set -e
export DEPLOY_GHOST=true export DEPLOY_GHOST=true
export DEPLOY_CLAMS=false export DEPLOY_CLAMS=false
export DEPLOY_NOSTR=false
export DEPLOY_NEXTCLOUD=false export DEPLOY_NEXTCLOUD=false
export DEPLOY_GITEA=false export DEPLOY_GITEA=false
@ -74,10 +74,10 @@ export NOSTR_RELAY_IMAGE="scsibug/nostr-rs-relay"
export WWW_SERVER_MAC_A DDRESS= export WWW_SERVER_MAC_A DDRESS=
export BTCPAYSERVER_MAC_ADDRESS= export BTCPAYSERVER_MAC_ADDRESS=
export SS_ROOT_PATH="$HOME/.ss" export SS_ROOT_PATH="$HOME/ss"
export REMOTES_DIR="$SS_ROOT_PATH/remotes" export REMOTES_PATH="$SS_ROOT_PATH/remotes"
export PROJECTS_DIR="$SS_ROOT_PATH/projects" export PROJECTS_PATH="$SS_ROOT_PATH/projects"
export SITES_PATH="$SS_ROOT_PATH/sites" export SITES_PATH="$SS_ROOT_PATH/sites"
# mount into ss-mgmt/home/ubuntu/snap/lxd/common/config # mount into ss-mgmt/home/ubuntu/snap/lxd/common/config
@ -96,19 +96,29 @@ export OTHER_SITES_LIST=
export BTCPAY_ALT_NAMES= export BTCPAY_ALT_NAMES=
export BITCOIN_CHAIN=regtest export BITCOIN_CHAIN=regtest
export REMOTE_HOME="/home/ubuntu" 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"
export BTCPAY_SERVER_APPPATH="$REMOTE_HOME/btcpayserver-docker" # this space is for OS, docker images, etc
export REMOTE_CERT_BASE_DIR="$REMOTE_HOME/.certs" # 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
# 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 REGISTRY_URL="https://index.docker.io/v1"
export PRIMARY_DOMAIN= export PRIMARY_DOMAIN=
# this is the git commit of the project/ sub git repo. # this is the git commit of the project/ sub git repo.
# used in the migration script to switch into past for backup # used in the migration script to switch into past for backup
# then back to present (TARGET_PROJECT_GIT_COMMIT) for restore. # then back to present (TARGET_PROJECT_GIT_COMMIT) for restore.
export TARGET_PROJECT_GIT_COMMIT=7a710d09162f98fa38e4c60fa00c87c8bcbeb5e9 export TARGET_PROJECT_GIT_COMMIT=f05daa9bfb11242eab920fdc4dd490d9bfdd6fbb
# #
export TESTNET_BLOCK_HASH=00000000d8277ba1ca66b40b3e3476629e6f0f97c5b8cfaeabfe402e55db223a export TESTNET_BLOCK_HASH=00000000d8277ba1ca66b40b3e3476629e6f0f97c5b8cfaeabfe402e55db223a

View File

@ -1,102 +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
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

95
deployment/down.sh Executable file
View File

@ -0,0 +1,95 @@
#!/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,12 +2,13 @@
You are in the Sovereign Stack Management Environment (SSME). From here, you can issue several commands: 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-remote - Take a remote SSH endpoint under management of Sovereign Stack.
ss-deploy - Deploys Sovereign Stack instances to your currenty remote according to your ss-reset - The opposite of ss-remote; de-provisions an existing remote.
ss-up - Instantiate a deployment to your active project according to your
various remote.conf, project.conf, and site.conf files. 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-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: For more infomation about all these topics, consult the Sovereign Stack website starting with:

View File

@ -1,8 +1,19 @@
#!/bin/bash #!/bin/bash
set -eu 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" PROJECT_DEFINITION_PATH="$PROJECT_PATH/project.conf"
@ -27,8 +38,13 @@ fi
source "$PRIMARY_SITE_DEFINITION_PATH" source "$PRIMARY_SITE_DEFINITION_PATH"
if ! lxc info | grep "project:" | grep -q "$PROJECT_NAME"; then SHASUM_OF_PRIMARY_DOMAIN="$(echo -n "$PRIMARY_DOMAIN" | sha256sum | awk '{print $1;}' )"
if lxc project list | grep -q "$PROJECT_NAME"; then export PRIMARY_DOMAIN_IDENTIFIER="${SHASUM_OF_PRIMARY_DOMAIN: -6}"
lxc project switch "$PROJECT_NAME"
fi export WWW_SSDATA_DISK_SIZE_GB="$WWW_SSDATA_DISK_SIZE_GB"
fi 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"

View File

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

View File

@ -1,7 +1,6 @@
#!/bin/bash #!/bin/bash
set -eu set -eu
cd "$(dirname "$0")"
CURRENT_REMOTE="$(lxc remote get-default)" CURRENT_REMOTE="$(lxc remote get-default)"
@ -26,7 +25,7 @@ if echo "$CURRENT_REMOTE" | grep -q "production"; then
fi fi
export REMOTE_PATH="$REMOTES_DIR/$CURRENT_REMOTE" export REMOTE_PATH="$REMOTES_PATH/$CURRENT_REMOTE"
REMOTE_DEFINITION="$REMOTE_PATH/remote.conf" REMOTE_DEFINITION="$REMOTE_PATH/remote.conf"
export REMOTE_DEFINITION="$REMOTE_DEFINITION" export REMOTE_DEFINITION="$REMOTE_DEFINITION"
@ -38,3 +37,50 @@ if [ ! -f "$REMOTE_DEFINITION" ]; then
fi fi
source "$REMOTE_DEFINITION" 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 source ../defaults.sh
./destroy.sh ./down.sh
# these only get initialzed upon creation, so we MUST delete here so they get recreated. # 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 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 lxc profile device remove default eth0
fi fi
if lxc network list --format csv | grep -q lxdbr0; then if lxc network list --format csv -q --project default | grep -q lxdbr0; then
lxc network delete lxdbr0 lxc network delete lxdbr0 --project default
fi fi
if lxc network list --format csv | grep -q lxdbr1; then if lxc network list --format csv -q --project default | grep -q lxdbr1; then
lxc network delete lxdbr1 lxc network delete lxdbr1 --project default
fi fi
# create the testnet/mainnet blocks/chainstate subvolumes. # # create the testnet/mainnet blocks/chainstate subvolumes.
for CHAIN in mainnet testnet; do # for CHAIN in mainnet testnet; do
for DATA in blocks chainstate; do # for DATA in blocks chainstate; do
if lxc storage volume list ss-base | grep -q "$CHAIN-$DATA"; then # if lxc storage volume list ss-base | grep -q "$CHAIN-$DATA"; then
lxc storage volume delete ss-base "$CHAIN-$DATA" # lxc storage volume delete ss-base "$CHAIN-$DATA"
fi # fi
done # done
done # done
if lxc storage list --format csv | grep -q ss-base; then if lxc storage list --format csv | grep -q ss-base; then
lxc storage delete ss-base lxc storage delete ss-base

View File

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

View File

@ -22,54 +22,10 @@ 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
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"
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 . ./project_env.sh
# Check to see if any of the VMs actually don't exist. # Check to see if any of the VMs actually don't exist.
@ -112,18 +68,25 @@ for PROJECT_CHAIN in ${DEPLOYMENT_STRING//,/ }; do
cd - cd -
# run deploy which backups up everything, but doesnt restart any services. # 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" bash -c "./project/deploy.sh --stop --backup-archive-path=$BTCPAY_RESTORE_ARCHIVE_PATH --backup-www --backup-btcpayserver"
# call the destroy script. If user proceed, then user data is DESTROYED! # call the down script (be default it is non-destructuve of user data.)
bash -c "./destroy.sh --project=$PROJECT_NAME" ./down.sh
# next we switch back to the current version of Sovereign Stack scripts for bringin up the new version.
cd project/ cd project/
echo "INFO: switching the 'project' repo back to the most recent commit '$TARGET_PROJECT_GIT_COMMIT'" 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." echo " That way new deployments will be instantiated using the latest codebase."
git checkout "$TARGET_PROJECT_GIT_COMMIT" git checkout "$TARGET_PROJECT_GIT_COMMIT"
cd - 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 # 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 #!/bin/bash
set -exu set -eu
cd "$(dirname "$0")" cd "$(dirname "$0")"
# see https://www.sovereign-stack.org/management/ # https://www.sovereign-stack.org/install/
# this script is not meant to be executed from the SSME; Let's let's check and abort if so. # 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 if [ "$(hostname)" = ss-mgmt ]; then
@ -19,13 +19,6 @@ fi
DISK="rpool/lxd" DISK="rpool/lxd"
export DISK="$DISK" 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 # install lxd snap and initialize it
if ! snap list | grep -q lxd; then if ! snap list | grep -q lxd; then
sudo snap install lxd --channel=latest/candidate sudo snap install lxd --channel=latest/candidate
@ -86,48 +79,68 @@ fi
# if the ss-mgmt doesn't exist, create it. # if the ss-mgmt doesn't exist, create it.
SSH_PUBKEY_PATH="$HOME/.ssh/id_rsa.pub" SSH_PUBKEY_PATH="$HOME/.ssh/id_rsa.pub"
FROM_BUILT_IMAGE=false
if ! lxc list --format csv | grep -q ss-mgmt; then 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 lxc init "images:$BASE_LXC_IMAGE" ss-mgmt --vm -c limits.cpu=4 -c limits.memory=4GiB --profile=default
fi
fi
# mount the pre-verified sovereign stack git repo into the new vm # 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 lxc config device add ss-mgmt ss-code disk source="$(pwd)" path=/home/ubuntu/sovereign-stack
fi
# create the ~/.ss path and mount it into the vm. # create the ~/ss path and mount it into the vm.
mkdir -p "$SS_ROOT_PATH" 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. if ! lxc config device show ss-mgmt | grep -q ss-root; then
BITCOIN_DIR="$HOME/.bitcoin" lxc config device add ss-mgmt ss-root disk source="$SS_ROOT_PATH" path=/home/ubuntu/ss
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. # # if a ~/.bitcoin/testnet3/blocks direrectory exists, mount it in.
BITCOIN_TESTNET_CHAINSTATE_PATH="$BITCOIN_DIR/testnet3/chainstate" # BITCOIN_DIR="$HOME/.bitcoin"
if [ -d "$BITCOIN_TESTNET_CHAINSTATE_PATH" ]; then # REMOTE_BITCOIN_CACHE_PATH="/home/ubuntu/ss/cache/bitcoin"
lxc config device add ss-mgmt ss-testnet-chainstate disk source="$BITCOIN_TESTNET_CHAINSTATE_PATH" path=$REMOTE_BITCOIN_CACHE_PATH/testnet/chainstate # BITCOIN_TESTNET_BLOCKS_PATH="$BITCOIN_DIR/testnet3/blocks"
fi # 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/blocks dir exists, mount it in. # # if a ~/.bitcoin/testnet3/blocks direrectory exists, mount it in.
BITCOIN_MAINNET_BLOCKS_PATH="$BITCOIN_DIR/blocks" # BITCOIN_TESTNET_CHAINSTATE_PATH="$BITCOIN_DIR/testnet3/chainstate"
if [ -d "$BITCOIN_MAINNET_BLOCKS_PATH" ]; then # if [ -d "$BITCOIN_TESTNET_CHAINSTATE_PATH" ]; then
lxc config device add ss-mgmt ss-mainnet-blocks disk source="$BITCOIN_MAINNET_BLOCKS_PATH" path=$REMOTE_BITCOIN_CACHE_PATH/mainnet/blocks # if ! lxc config device show ss-mgmt | grep -q ss-testnet-chainstate; then
else # lxc config device add ss-mgmt ss-testnet-chainstate disk source="$BITCOIN_TESTNET_CHAINSTATE_PATH" path=$REMOTE_BITCOIN_CACHE_PATH/testnet/chainstate
echo "INFO: the blocks directory was not found for mainnet. It will NOT be mounted into ss-mgmt." # fi
fi # fi
# if a ~/.bitcoin/testnet3/blocks direrectory exists, mount it in. # # if a ~/.bitcoin/blocks dir exists, mount it in.
BITCOIN_MAINNET_CHAINSTATE_PATH="$BITCOIN_DIR/chainstate" # BITCOIN_MAINNET_BLOCKS_PATH="$BITCOIN_DIR/blocks"
if [ -d "$BITCOIN_MAINNET_CHAINSTATE_PATH" ]; then # if [ -d "$BITCOIN_MAINNET_BLOCKS_PATH" ]; then
lxc config device add ss-mgmt ss-mainnet-chainstate disk source="$BITCOIN_MAINNET_CHAINSTATE_PATH" path=$REMOTE_BITCOIN_CACHE_PATH/mainnet/chainstate # if ! lxc config device show ss-mgmt | grep -q ss-mainnet-blocks; then
else # lxc config device add ss-mgmt ss-mainnet-blocks disk source="$BITCOIN_MAINNET_BLOCKS_PATH" path=$REMOTE_BITCOIN_CACHE_PATH/mainnet/blocks
echo "INFO: the chainstate directory was not found for mainnet. It will NOT be mounted into ss-mgmt." # fi
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. # mount the ssh directory in there.
if [ -f "$SSH_PUBKEY_PATH" ]; then if [ -f "$SSH_PUBKEY_PATH" ]; then
if ! lxc config device show ss-mgmt | grep -q ss-ssh; then
lxc config device add ss-mgmt ss-ssh disk source="$HOME/.ssh" path=/home/ubuntu/.ssh lxc config device add ss-mgmt ss-ssh disk source="$HOME/.ssh" path=/home/ubuntu/.ssh
fi fi
fi fi
@ -176,15 +189,25 @@ 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" sudo chown -R ubuntu:ubuntu /home/ubuntu
if [ "$FROM_BUILT_IMAGE" = false ]; then
ssh "ubuntu@$IP_V4_ADDRESS" /home/ubuntu/sovereign-stack/management/provision.sh ssh "ubuntu@$IP_V4_ADDRESS" /home/ubuntu/sovereign-stack/management/provision.sh
#lxc restart ss-mgmt 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
if [ "$ADDED_COMMAND" = true ]; then 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." echo "NOTICE! You need to run 'source ~/.bashrc' before continuing. After that, type 'ss-manage' to enter your management environment."
fi fi
. ./defaults.sh . ./defaults.sh
# As part of the install script, we pull down any other sovereign-stack git repos # 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_REPO_URL="https://git.sovereign-stack.org/ss/project"
PROJECTS_SCRIPTS_PATH="$(pwd)/deployment/project" PROJECTS_SCRIPTS_PATH="$(pwd)/deployment/project"

View File

@ -1,8 +1,16 @@
#!/bin/bash #!/bin/bash
# https://www.sovereign-stack.org/ss-manage/
set -eu set -eu
cd "$(dirname "$0")" 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 if ! lxc remote get-default | grep -q "local"; then
lxc remote switch "local" lxc remote switch "local"
fi 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-show='/home/ubuntu/sovereign-stack/deployment/show.sh $@'
alias ss-reset='/home/ubuntu/sovereign-stack/deployment/reset.sh $@' alias ss-reset='/home/ubuntu/sovereign-stack/deployment/reset.sh $@'
alias ss-update='/home/ubuntu/sovereign-stack/deployment/update.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 ss-help='cat /home/ubuntu/sovereign-stack/deployment/help.txt'
alias ll='ls -lah' alias ll='ls -lah'

View File

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