From b5a48ef23ef9d0eefbdcd9071b9148e20163cfad Mon Sep 17 00:00:00 2001 From: Derek Smith Date: Sun, 9 Oct 2022 20:35:02 -0400 Subject: [PATCH] Updates to migration restoration. --- cluster.sh | 286 +++++++++++++-------------- deployment/www/stop_docker_stacks.sh | 4 +- reset_env.sh | 2 +- 3 files changed, 141 insertions(+), 151 deletions(-) diff --git a/cluster.sh b/cluster.sh index 6ce1707..7b1d8dd 100755 --- a/cluster.sh +++ b/cluster.sh @@ -7,31 +7,26 @@ cd "$(dirname "$0")" # it reaches out to an SSH endpoint and provisions that machine # to use LXD. -COMMAND="${1:-}" DATA_PLANE_MACVLAN_INTERFACE= DISK_TO_USE=loop -if [ "$COMMAND" = create ]; then +# override the cluster name. +CLUSTER_NAME="${1:-}" +if [ -z "$CLUSTER_NAME" ]; then + echo "ERROR: The cluster name was not provided." + exit 1 +fi - # override the cluster name. - CLUSTER_NAME="${2:-}" - +#shellcheck disable=SC1091 +source ./defaults.sh - if [ -z "$CLUSTER_NAME" ]; then - echo "ERROR: The cluster name was not provided." - exit 1 - fi +export CLUSTER_PATH="$CLUSTERS_DIR/$CLUSTER_NAME" +CLUSTER_DEFINITION="$CLUSTER_PATH/cluster_definition" +export CLUSTER_DEFINITION="$CLUSTER_DEFINITION" - #shellcheck disable=SC1091 - source ./defaults.sh - - export CLUSTER_PATH="$CLUSTERS_DIR/$CLUSTER_NAME" - CLUSTER_DEFINITION="$CLUSTER_PATH/cluster_definition" - export CLUSTER_DEFINITION="$CLUSTER_DEFINITION" - - mkdir -p "$CLUSTER_PATH" - if [ ! -f "$CLUSTER_DEFINITION" ]; then - # stub out a cluster_definition. +mkdir -p "$CLUSTER_PATH" +if [ ! -f "$CLUSTER_DEFINITION" ]; then + # stub out a cluster_definition. cat >"$CLUSTER_DEFINITION" </dev/null 2>&1; then + if lxc profile list --format csv | grep -q sovereign-stack; then + lxc profile delete sovereign-stack + sleep 1 fi - # The MGMT Plane IP is the IP address that the LXD API binds to, which happens - # to be the same as whichever SSH connection you're coming in on. - MGMT_PLANE_IP="$(ssh ubuntu@"$FQDN" env | grep SSH_CONNECTION | cut -d " " -f 3)" - IP_OF_MGMT_MACHINE="$(ssh ubuntu@"$FQDN" env | grep SSH_CLIENT | cut -d " " -f 1 )" - IP_OF_MGMT_MACHINE="${IP_OF_MGMT_MACHINE#*=}" - IP_OF_MGMT_MACHINE="$(echo "$IP_OF_MGMT_MACHINE" | cut -d: -f1)" - - # error out if the cluster password is unset. - if [ -z "$LXD_CLUSTER_PASSWORD" ]; then - echo "ERROR: LXD_CLUSTER_PASSWORD must be set in your cluster_definition." - exit 1 + if lxc network list --format csv | grep -q lxdbrSS; then + lxc network delete lxdbrSS + sleep 1 fi +fi - if ! command -v lxc >/dev/null 2>&1; then - if lxc profile list --format csv | grep -q sovereign-stack; then - lxc profile delete sovereign-stack - sleep 1 - fi - - if lxc network list --format csv | grep -q lxdbrSS; then - lxc network delete lxdbrSS - sleep 1 - fi - fi - - ssh -t "ubuntu@$FQDN" " +ssh -t "ubuntu@$FQDN" " # set host firewall policy. # allow LXD API from management network. # sudo ufw allow from ${IP_OF_MGMT_MACHINE}/32 proto tcp to $MGMT_PLANE_IP port 8443 @@ -176,15 +171,15 @@ if ! snap list | grep -q lxd; then sleep 4 fi " - # if the DATA_PLANE_MACVLAN_INTERFACE is not specified, then we 'll - # just attach VMs to the network interface used for for the default route. - if [ -z "$DATA_PLANE_MACVLAN_INTERFACE" ]; then - DATA_PLANE_MACVLAN_INTERFACE="$(ssh -t ubuntu@"$FQDN" ip route | grep default | cut -d " " -f 5)" - fi +# if the DATA_PLANE_MACVLAN_INTERFACE is not specified, then we 'll +# just attach VMs to the network interface used for for the default route. +if [ -z "$DATA_PLANE_MACVLAN_INTERFACE" ]; then + DATA_PLANE_MACVLAN_INTERFACE="$(ssh -t ubuntu@"$FQDN" ip route | grep default | cut -d " " -f 5)" +fi - # stub out the lxd init file for the remote SSH endpoint. - CLUSTER_MASTER_LXD_INIT="$CLUSTER_PATH/lxdinit_profile.yml" - cat >"$CLUSTER_MASTER_LXD_INIT" <"$CLUSTER_MASTER_LXD_INIT" <