Last active
December 23, 2021 18:38
-
-
Save urjitbhatia/add0add7ff2b1f4bcb799b7cb8ba24af to your computer and use it in GitHub Desktop.
Drain a nomad EC2 spot instance node on termination
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 | |
CMD="curl --write-out %{http_code} --silent --output /dev/null http://169.254.169.254/latest/meta-data/spot/termination-time" | |
while true | |
do | |
if [ "$(${CMD})" != "404" ]; then | |
# 2 minute warning received. Do all your cleanup work. | |
echo "2 minute termination warning. Draining nomad node..." | |
nomad node-drain -yes -self -enable | |
echo "Hasta la vista baby, I will be back" | |
break | |
else | |
echo "Not terminating yet..." | |
# Still running fine, sleep and then check again | |
sleep 10 | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment