#!/bin/bash set -eux cd "$(dirname "$0")" # NOTE This script is meant to be executed on your LXD bare metal servers. This script # ensures that the LXD daemon is installed via snap package, then initialize the daemon # to operate in clustered mode COMMAND="${1:-}" DATA_PLANE_MACVLAN_INTERFACE= DISK_TO_USE=loop if [ "$COMMAND" = create ]; then # override the cluster name. CLUSTER_NAME="${2:-}" if [ -z "$CLUSTER_NAME" ]; then echo "ERROR: The cluster name was not provided." exit 1 fi #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. 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 if lxc network list --format csv | grep -q lxdbr0; then lxc network delete lxdbr0 sleep 1 fi fi 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 # enable it. if sudo ufw status | grep -q 'Status: inactive'; then sudo ufw enable fi # install lxd as a snap if it's not installed. We only really use the LXC part of this package. if ! snap list | grep -q lxd; then sudo -A snap install lxd 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 # stub out the lxd init file for the remote SSH endpoint. CLUSTER_MASTER_LXD_INIT="$CLUSTER_PATH/$CLUSTER_NAME-primary.yml" cat >"$CLUSTER_MASTER_LXD_INIT" <