Skip to content

Instantly share code, notes, and snippets.

@djsutherland
Last active October 28, 2015 22:36
Show Gist options
  • Save djsutherland/b41a5adc1171a7cc9ea9 to your computer and use it in GitHub Desktop.
Save djsutherland/b41a5adc1171a7cc9ea9 to your computer and use it in GitHub Desktop.
Watch for termination of spot instance, SIGHUP passed process if so.
#!/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