Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
89412: gceworker: change cron job to ignore /.active after 2 days r=ajwerner a=ajwerner

It's easy to forget that you've left your gceworker running when you touch /.active. This leads to lots of wasted resources. Here we change the definition of /.active to only count it if the mod time is less than two days ago. This may prove to be frustrating for some folks, but those folks can set the mod time to something in the future or set something else in their enviroment to regularly touch the file. Also, it's easy enough for anybody who is so inclined to change the script to meet their needs on their own gceworker. This should be a more sane default.

Release note: None

Co-authored-by: Andrew Werner <awerner32@gmail.com>
  • Loading branch information
craig[bot] and ajwerner committed Oct 6, 2022
2 parents 1f7d3ba + 962ce40 commit 712ee6b
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion build/bootstrap/autoshutdown.cron.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,24 @@ fi
FILE=/dev/shm/autoshutdown-count
COUNT=0

# We ignore active if it has not been modified in the last two
# days. If one must keep their GCE worker alive longer than that
# without touching the file in the middle, you can set the mod
# time on the file into the future. To set a mod time to the future
# you can use `touch -t [[CC]YY]MMDDhhmm /.active`.
ACTIVE_FILE=/.active
AUTO_SHUTDOWN_DURATION=$(( 2 * 24 * 60 * 60 ))

if [ -f /.active ] || w -hs | grep pts | grep -vq "pts/[0-9]* *tmux" || pgrep unison || pgrep -f remote-dev-server.sh; then
active_exists() {
if [[ ! -f "$ACTIVE_FILE" ]]; then
return 1
fi
active=$(date -r "$ACTIVE_FILE" +%s)
age=$(( $(date +%s) - $active ))
[[ $age -lt $AUTO_SHUTDOWN_DURATION ]]
}

if active_exists || w -hs | grep pts | grep -vq "pts/[0-9]* *tmux" || pgrep unison || pgrep -f remote-dev-server.sh; then
# Auto-shutdown is disabled (via /.active) or there is a remote session.
echo 0 > $FILE
exit 0
Expand All @@ -50,5 +66,6 @@ if [ -z "${1-}" ]; then
/sbin/shutdown -h
else
# Run whatever command was passed on the command line.
# shellcheck disable=SC2068
$@
fi

0 comments on commit 712ee6b

Please sign in to comment.