Skip to content

Commit

Permalink
[ci skip] 2024.09.09-31341
Browse files Browse the repository at this point in the history
  • Loading branch information
cybozu-neco committed Sep 9, 2024
2 parents 68404de + 7c408f0 commit 7dbb53e
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 2 deletions.
4 changes: 2 additions & 2 deletions debian/DEBIAN/prerm
Original file line number Diff line number Diff line change
@@ -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
Expand Down
15 changes: 15 additions & 0 deletions debian/lib/systemd/system/trigger-reboot-all-nodes.service
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions debian/lib/systemd/system/trigger-reboot-all-nodes.timer
Original file line number Diff line number Diff line change
@@ -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
31 changes: 31 additions & 0 deletions debian/usr/bin/trigger-reboot-all-nodes
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 7dbb53e

Please sign in to comment.