Last active
August 16, 2018 20:14
-
-
Save marxjohnson/0116f8b7e1d7ecb86860e097c9d307ef to your computer and use it in GitHub Desktop.
UPS canary script
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
# Ping the specified host (argument $1). If it's not there, wait 30 seconds and try again. | |
# If its not there for 2 minutes, do a clean shutdown. | |
# The host should be connected to the nextwork and plugged into a socket that's not backed up by the UPS. | |
# This should be run on a host that is backed up by the UPS, on a cron job. | |
tail -c 10000 /var/log/canary.log > /var/log/canary.log | |
REBOOT=true | |
for e in a b c d | |
do | |
sleep 30 | |
if ping -c1 $1 | |
then | |
REBOOT=false | |
break | |
fi | |
done | |
if $REBOOT | |
then | |
echo "Canary has died, shutting down\n" | |
/sbin/shutdown -h now | |
fi | |
echo "Canary is alive, exiting\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment