UPS’s are truly great devices! They save your butt when you have a short power out, or grandma accidentally has her curling iron and hair dryer on at the same time. But with a known runtime, you need a way to gracefully shutdown your systems to prevent data loss. Well, with APC PowerChute not looking very friendly, I decided to just go out and make my own little tool, and here it is! May I present to you, UPSalert – My solution to graceful server shutdowns on power loss.
- This script was developed for Debian Linux, so I can not promise it will work on other distros without modifications.
- This script is currently designed for use with an APC UPS. If you have a different UPS, and would like a modified version similar to what this does, shoot me an email at chris (at) servernetworktech.com and I will see what I can do for you.
- A Server to host this script
- SSH Key Authentication between the Host and Servers (You can follow my guide on that Here)
- An APC UPS with SNMP Enabled
First thing you will need to do is SSH into the Server that will host the script, and install the required packages for the script. Remember to run apt-get as root.
apt-get update apt-get install snmp ping wakeonlan bsd-mailx
Now we will need to create the folder /opt/upsalert. After that you will need to download the script, and then make it executable.
mkdir /opt/upsalert wget http://servernetworktech.com/uploads/scripts/UPSalert.sh -O /opt/upsalert/UPSalert.sh chmod +x /opt/upsalert/UPSalert.sh
After this, you will need to configure the script, so just nano inside of it, and modify the values. This is where you define the MAC address and IPs of your servers, as well as your email and such.
Now is where I would recommend setting it to debug mode, and running it to make sure it works. After you test it, and are satisfied with the results, turn off debugging, add a cronjob to call the script, and away you go!
If you don’t want to use my guide, and you just want to setup the script on your own, then these are for you. I also included a Proxmox Version (which is what I use) for those of you who also want your cluster nodes to properly shutdown VM’s before halting the host. This helps prevent data loss.