Managing a server at home can be a fun and if you use Linux as your operating system it can also be a learning experience. I chose to run Ubuntu on my server since it has all the features of Linux but easy to get going quickly. Let me preface this by saying I have worked in the IT field for almost a year and consider myself proficient in Linux. I am by no means an expert but I know enough to get what I need done.
One of the problems I have run into lately is power outages. This is understandable when you run your server out of your own home however recently I have had three power outages in one week and was not only fed up with the downtime but worried abut the safety of my hard drives. So I did some research, calculated how long I needed my battery to last, how much power my server draws, and what brand to get. I’ll spare you the details but I ended up buying the Cyberpower 1350VA/810W pure sine wave UPS. After plugging everything, I fired up my Ubuntu box and it instantly saw the UPS and told me the expected battery run time and everything! No drivers or additional software. However, Ubuntu did not really manage what to do if the power goes but fortunately Cyberpower provides PowerPanel which is very powerful. This software is capable of triggering a script the second the power goes out which can email you and then also trigger a script when the battery goes low (low threshold is defined in the configuration). After configuring everything I decided to do a test run. With the battery at a 100% I pulled the plug and watched as everything I told it to do was executed and much to my delight it went very smooth! The only thing that failed was the email alert that I set it up to do. After looking into this I discovered it was a flaw in the PowerPanel predefined scripts and after some changes it worked!
So now I will discuss the changes I made along with the configuration I used. First up after installing the deb on Ubuntu open up /etc/pwrstatd-email.sh and replace the contents with the following: http://pastebin.com/UpKPcK38.
The modifications fixes two things: The variable $DATA was not being defined correctly in the default PowerPanel script and the mail headers were causing problems with the email being sent properly. Now with everything sorted lets go into my configuration located at /etc/pwrstatd.conf available here: http://pastebin.com/7frFrkUA.
One thing you will notice in the configuration is, ‘turn-ups-off = yes’. This is amazing since my server will power on when A/C is restored. What this allows me to do is shutdown the server when the battery is low then kill the UPS. When the UPS senses power is back it will fire itself back on and by doing so restoring power to the server which then boots back up! Here is what happens in english based on this configuration.
1) Power goes out and I instantly receive an email alert letting me know.
2) When battery reaches 15% (usually in 20 minutes) I get another email and the computer is then instructed to shutdown.
3) After 60 seconds of the server being told to shutdown the UPS shutsdown.
4) Once power is restored the UPS fires up in 5 seconds then server is back up as well!
As you can see this setup requires no user interaction which allows for remote management/services to continue despite a power outage!
I hope this helps someone since there were issues getting this working perfectly out of the box.