From 25139b514c1c35cf6673e6d1e1751043e1572388 Mon Sep 17 00:00:00 2001 From: Derek Smith Date: Sat, 5 Nov 2022 19:52:45 -0400 Subject: [PATCH] Refactors from AWS removal. --- deployment/deploy_vms.sh | 47 ++++++++++++++++++++++--------------- deployment/provision_lxc.sh | 18 -------------- deployment/run_ddns.sh | 29 ----------------------- 3 files changed, 28 insertions(+), 66 deletions(-) delete mode 100755 deployment/provision_lxc.sh delete mode 100755 deployment/run_ddns.sh diff --git a/deployment/deploy_vms.sh b/deployment/deploy_vms.sh index f197c45..acd8505 100755 --- a/deployment/deploy_vms.sh +++ b/deployment/deploy_vms.sh @@ -26,23 +26,6 @@ EOF fi -function prepare_host { - # scan the remote machine and install it's identity in our SSH known_hosts file. - ssh-keyscan -H -t ecdsa "$FQDN" >> "$SSH_HOME/known_hosts" - - # create a directory to store backup archives. This is on all new vms. - ssh "$FQDN" mkdir -p "$REMOTE_HOME/backups" - - # if this execution is for btcpayserver, then we run the stub/btcpay setup script - # but only if it hasn't been executed before. - if [ "$VIRTUAL_MACHINE" = btcpayserver ]; then - if [ "$(ssh "$BTCPAY_FQDN" [[ ! -f "$REMOTE_HOME/btcpay.complete" ]]; echo $?)" -eq 0 ]; then - ./btcpayserver/stub_btcpay_setup.sh - fi - fi - -} - ssh-keygen -f "$SSH_HOME/known_hosts" -R "$FQDN" # if the machine doesn't exist, we create it. @@ -55,7 +38,33 @@ if ! lxc list --format csv | grep -q "$LXD_VM_NAME"; then exit 1 fi - ./provision_lxc.sh + ./stub_lxc_profile.sh "$LXD_VM_NAME" + + # now let's create a new VM to work with. + lxc init --profile="$LXD_VM_NAME" "$VM_NAME" "$LXD_VM_NAME" --vm + + # let's PIN the HW address for now so we don't exhaust IP + # and so we can set DNS internally. + lxc config set "$LXD_VM_NAME" "volatile.enp5s0.hwaddr=$MAC_ADDRESS_TO_PROVISION" + lxc config device override "$LXD_VM_NAME" root size="${ROOT_DISK_SIZE_GB}GB" + + lxc start "$LXD_VM_NAME" + + ./wait_for_lxc_ip.sh "$LXD_VM_NAME" + +fi + +# scan the remote machine and install it's identity in our SSH known_hosts file. +ssh-keyscan -H -t ecdsa "$FQDN" >> "$SSH_HOME/known_hosts" + +# create a directory to store backup archives. This is on all new vms. +ssh "$FQDN" mkdir -p "$REMOTE_HOME/backups" + +# if this execution is for btcpayserver, then we run the stub/btcpay setup script +# but only if it hasn't been executed before. +if [ "$VIRTUAL_MACHINE" = btcpayserver ]; then + if [ "$(ssh "$BTCPAY_FQDN" [[ ! -f "$REMOTE_HOME/btcpay.complete" ]]; echo $?)" -eq 0 ]; then + ./btcpayserver/stub_btcpay_setup.sh + fi fi -prepare_host diff --git a/deployment/provision_lxc.sh b/deployment/provision_lxc.sh deleted file mode 100755 index f641fff..0000000 --- a/deployment/provision_lxc.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash - -set -eu -cd "$(dirname "$0")" - -./stub_lxc_profile.sh "$LXD_VM_NAME" - -# now let's create a new VM to work with. -lxc init --profile="$LXD_VM_NAME" "$VM_NAME" "$LXD_VM_NAME" --vm - -# let's PIN the HW address for now so we don't exhaust IP -# and so we can set DNS internally. -lxc config set "$LXD_VM_NAME" "volatile.enp5s0.hwaddr=$MAC_ADDRESS_TO_PROVISION" -lxc config device override "$LXD_VM_NAME" root size="${ROOT_DISK_SIZE_GB}GB" - -lxc start "$LXD_VM_NAME" - -./wait_for_lxc_ip.sh "$LXD_VM_NAME" diff --git a/deployment/run_ddns.sh b/deployment/run_ddns.sh deleted file mode 100755 index 5e825b3..0000000 --- a/deployment/run_ddns.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/bash - -set -eu - -DDNS_STRING= - -# for the www stack, we register only the domain name so our URLs look like https://$DOMAIN_NAME -if [ "$VIRTUAL_MACHINE" = www ] || [ "$VIRTUAL_MACHINE" = certonly ]; then - DDNS_STRING="@" -else - DDNS_STRING="$DDNS_HOST" -fi - -# wait for DNS to get setup. Pass in the IP address of the actual VPS. -MACHINE_IP="$(docker-machine ip "$FQDN")" -DDNS_SLEEP_SECONDS=60 -while true; do - # we test the www CNAME here so we can be assured the underlying has corrected. - if [[ "$(getent hosts "$FQDN" | awk '{ print $1 }')" == "$MACHINE_IP" ]]; then - echo "" - echo "SUCCESS: The DNS appears to be configured correctly." - - echo "INFO: Waiting $DDNS_SLEEP_SECONDS seconds to allow cached DNS records to expire." - sleep "$DDNS_SLEEP_SECONDS"; - break; - fi - - printf "." && sleep 2; -done