diff --git a/debian/DEBIAN/prerm b/debian/DEBIAN/prerm index cfce05653..065fa6086 100755 --- a/debian/DEBIAN/prerm +++ b/debian/DEBIAN/prerm @@ -1,7 +1,7 @@ #!/bin/sh -e -SERVICES="neco-updater neco-worker node-exporter sabakan-state-setter neco-rebooter cke cke-localproxy teleport-node" -TIMERS="docker-prune kill-old-login-sessions backup-cke-etcd export-unit-status" +SERVICES="neco-updater neco-worker node-exporter sabakan-state-setter neco-rebooter cke cke-localproxy teleport-node trigger-reboot-all-nodes" +TIMERS="docker-prune kill-old-login-sessions backup-cke-etcd export-unit-status trigger-reboot-all-nodes" prerm() { for s in $SERVICES; do diff --git a/debian/lib/systemd/system/trigger-reboot-all-nodes.service b/debian/lib/systemd/system/trigger-reboot-all-nodes.service new file mode 100644 index 000000000..960f87d41 --- /dev/null +++ b/debian/lib/systemd/system/trigger-reboot-all-nodes.service @@ -0,0 +1,15 @@ +[Unit] +Description=Trigger reboot all nodes every night on dev environment +Wants=network-online.target cke.service sabakan.service neco-rebooter.service +After=network-online.target cke.service sabakan.service neco-rebooter.service +StartLimitIntervalSec=600s + +[Service] +Type=simple +Restart=on-failure +RestartForceExitStatus=SIGPIPE +RestartSec=30s +ExecStart=/usr/bin/trigger-reboot-all-nodes + +[Install] +WantedBy=multi-user.target diff --git a/debian/lib/systemd/system/trigger-reboot-all-nodes.timer b/debian/lib/systemd/system/trigger-reboot-all-nodes.timer new file mode 100644 index 000000000..67adff741 --- /dev/null +++ b/debian/lib/systemd/system/trigger-reboot-all-nodes.timer @@ -0,0 +1,11 @@ +[Unit] +Description=Trigger reboot all nodes every night on dev environment +After=network-online.target cke.service sabakan.service neco-rebooter.service + +[Timer] +# Every day at 18:00:00 (JST) +OnCalendar=*-*-* 09:00:00 +Persistent=true + +[Install] +WantedBy=timers.target diff --git a/debian/usr/bin/trigger-reboot-all-nodes b/debian/usr/bin/trigger-reboot-all-nodes new file mode 100755 index 000000000..376448c8f --- /dev/null +++ b/debian/usr/bin/trigger-reboot-all-nodes @@ -0,0 +1,31 @@ +#!/bin/sh +CKECLI_COMMAND="/usr/bin/ckecli" +NECO_COMMAND="/usr/bin/neco" +UNAME_COMMAND="/usr/bin/uname" +YES_COMMAND="/usr/bin/yes" + +ENVIROMENT=$(${NECO_COMMAND} config get env) +if [ "$ENVIROMENT" != "dev" ]; then + echo "This script is only for dev environment" + exit 0 +fi + +# Confirm that host is a learder +HOSTNAME=$(${UNAME_COMMAND} -n) +LEADER=$(${NECO_COMMAND} rebooter leader) +if [ "$HOSTNAME" != "$LEADER" ]; then + echo "This host is not a leader. Skipping reboot all nodes" + exit 0 +fi + +REBOOT_LIST=$(${NECO_COMMAND} rebooter list) +REBOOT_QUEUE=$(${CKECLI_COMMAND} rq list) +# Confirm that the reboot list and reboot queue are empty +if [ "$REBOOT_LIST" != "null" ] || [ "$REBOOT_QUEUE" != "null" ]; then + echo "The reboot list or reboot queueu is not empty. Skipping reboot all nodes" + exit 0 +fi + +$NECO_COMMAND rebooter disable +sh -c $YES_COMMAND | $NECO_COMMAND rebooter reboot-worker --without-state retiring,retired +$NECO_COMMAND rebooter enable