Files
platform/bin/teardown.sh
2020-11-19 13:20:13 +01:00

45 lines
1.1 KiB
Bash
Executable File

#!/usr/bin/env bash
TOP="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )/.."
reboot=yes
case $1 in
--no-reboot) reboot=no; shift ;;
esac
if [ $# != 1 ]; then
echo "usage: teardown.sh [--reboot] name"
exit 1
fi
d=$1
tmp=$TOP/clusters/$d/.$d.$$
teardown () {
sed '/k8s *= *{/,+1 s/enable *= *true/enable = false/' \
$TOP/clusters/$d/default.nix > $tmp
nixops modify -d $d $tmp
nixops deploy -d $d
[ $reboot = yes ] && nixops reboot -d $d
nixops ssh-for-each -d $d \
"rm -rf /var/run/kubernetes /var/lib/kubernetes /var/lib/etcd /var/lib/kubelet /var/lib/cfssl"
rm $tmp
}
cat << EOF
************************************************************************
*** ***
*** WARNING: This will irrevokably destroy the running cluster! ***
*** ***
************************************************************************
EOF
echo "Are you sure you want to tear down $d? (YES/no)"
read a
case $a in
YES) teardown ;;
*) echo "Bailing out." ;;
esac