Skip to content

Instantly share code, notes, and snippets.

@byrnedo
Created March 7, 2024 10:21
Show Gist options
  • Save byrnedo/d1af120cdc8b22d43a8bfc7633d08230 to your computer and use it in GitHub Desktop.
Save byrnedo/d1af120cdc8b22d43a8bfc7633d08230 to your computer and use it in GitHub Desktop.
Start a multipass n node cluster, and handle it easily.
#!/bin/bash
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
POSITIONAL_ARGS=()
while [[ $# -gt 0 ]]; do
case $1 in
# -e|--extension)
# EXTENSION="$2"
# shift # past argument
# shift # past value
# ;;
-* | --*)
echo "Unknown option $1"
exit 1
;;
*)
POSITIONAL_ARGS+=("$1") # save positional arg
shift # past argument
;;
esac
done
nodes=2
# shellcheck disable=SC2128
case "$POSITIONAL_ARGS" in
create)
cat <<EOF >/tmp/cluster-plz.yaml
users:
- default
- name: $(echo $USER)
sudo: ALL=(ALL) NOPASSWD:ALL
ssh_authorized_keys:
- $(cat ~/.ssh/id_rsa.pub)
packages:
- make
- gcc
- libssl-dev
- pkg-config
EOF
for f in $(seq $nodes); do
multipass launch -c 1 -m 1G -d 7G -n node-$f --cloud-init /tmp/cluster-plz.yaml --mount "${SCRIPT_DIR}/../:/home/ubuntu/skate"
done
for f in $(seq $nodes); do
multipass snapshot node-$f
done
for f in $(seq $nodes); do
multipass info node-$f
done
;;
info)
for f in $(seq $nodes); do
multipass info node-$f
done
;;
ips)
for f in $(seq $nodes); do
multipass info node-$f | grep IPv4 | awk '{print $2}'
done
;;
restore)
for f in $(seq $nodes); do
multipass restore "node-${f}.in"
done
;;
remove)
for f in $(seq $nodes); do
multipass delete --purge "node-${f}"
done
;;
shell)
SESSION="clusterplz"
tmux kill-session -t $SESSION
tmux new-session -d -s $SESSION
# todo, split $nodes-1 times
for f in $(seq $nodes); do
tmux send-keys -t $SESSION "multipass shell node-$f" Enter
if [ $f -ne $nodes ]; then
tmux split-window -h -t $SESSION
fi
done
tmux attach-session -t $SESSION
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment