Created
October 28, 2024 15:40
-
-
Save deads2k/ca34a28a93ca01e04498ec036cc910e0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
trap 'echo "Caught interrupt! Gracefully delete 25s sleep to let another pod start..."; sleep 25; exit 0' INT | |
while true; do | |
echo "Sleeping for 1h..." | |
sleep 3600 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If Bash is waiting for a command to complete and receives a signal for which a trap has been set, the trap will not be executed until the command completes.
Bash will interrupt
wait
, so one option is to backgroundsleep
and block onwait
waiting for thesleep
call to finish.Technically, the background
sleep
call will still run to completion, but theexit
in thetrap
takes care of that.