Last active
October 28, 2015 22:36
-
-
Save djsutherland/b41a5adc1171a7cc9ea9 to your computer and use it in GitHub Desktop.
Watch for termination of spot instance, SIGHUP passed process if so.
This file contains hidden or 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 | |
pid=$1 | |
echo "Watching for spot instance termination; will SIGHUP $pid if so." | |
while kill -0 $pid >/dev/null 2>/dev/null; do | |
if curl -s http://169.254.169.254/latest/meta-data/spot/termination-time | grep -q .*T.*Z; then | |
echo 'oh noes! telling caffe to snapshot.' | |
kill -SIGHUP $pid | |
fi | |
sleep 5; | |
done | |
echo "$pid ended, and we're still alive. Huzzah!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment