From 646016818c651c54d0cce67600a756c2bbd5dc5c Mon Sep 17 00:00:00 2001 From: Chris Evich Date: Thu, 14 Dec 2023 11:57:43 -0500 Subject: [PATCH] Fix two pool service script failure-modes Fix typo in calculating sleep seconds. Remove mode `e` from script, so any failing command (i.e. a pgrep) doesn't cause the script to exit. Also redirect null input into shutdown command, since it can behaves oddly otherwise. Signed-off-by: Chris Evich --- mac_pw_pool/service_pool.sh | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/mac_pw_pool/service_pool.sh b/mac_pw_pool/service_pool.sh index 2aa74df..61029aa 100644 --- a/mac_pw_pool/service_pool.sh +++ b/mac_pw_pool/service_pool.sh @@ -6,7 +6,7 @@ # Expects the number of hours until shutdown (and self-termination) # as the second argument. -set -eo pipefail +set -o pipefail msg() { echo "##### ${1:-No message message provided}"; } die() { echo "ERROR: ${1:-No error message provided}"; exit 1; } @@ -65,13 +65,12 @@ while [[ -r $PWCFG ]]; do if pgrep -u $PWUSER -q "cirrus-ci-agent"; then msg "$(date -u -Iseconds) Shutdown paused 2h for apparent in-flight CI task." # Cirrus-CI has hard-coded 2-hour max task lifetime - sleep $(60 * 60 * 2) + sleep $((60 * 60 * 2)) msg "$(date -u -Iseconds) Killing hung or nefarious CI agent older than 2h." sudo pkill -u $PWUSER "cirrus-ci-agent" fi msg "$(date -u -Iseconds) Executing shutdown." - sudo shutdown -h +1m "Automatic instance recycle after >$PWLIFE hours." - sleep 10 + sudo shutdown -h now "Automatic instance recycle after >$PWLIFE hours." < /dev/null fi # Avoid re-launch busy-wait