24
3
I have a home server (HP Proliant ML310 G4) that I bought from my employer a month or so ago. The server runs Debian Linux and I use it for just about everything. I can get away with doing this because my needs aren't that demanding so the server is rarely under heavy loads at any given time. This server has a 2 TB RAID1 array (with one hot spare) managed by mdadm that I use for file sharing over my network via Samba. I'm running the OS off a smaller hard drive that is not part of the array.
I have the server powered through a small 255-watt UPS because I need it to withstand minor power fluctuations without coming down. This is very important because a sudden unclean shutdown (caused by a power drop or blackout) can screw up the RAID array, which has already happened on one occasion.
In the event of a power failure, I'm estimating the UPS has only 10-15 minutes of power in it. There may be more but I don't want to automatically assume there is. This is enough to get through blackouts that last a few minutes or less. However, if the power is down for several hours I need the server to properly shut itself down automatically before the UPS power fails. This will hopefully keep the RAID integrity from getting hosed in those situations.
This sort of thing is easy on a laptop b/c it has built-in sensors to determine when it is running on battery power, but this server does not (as far as I know). I have an unusual network setup where my DSL modem is separate from my router. The router is also on the UPS, which allows me to SSH in through my laptop and shut down the server in the event of a power failure. Unfortunately, this only works if I'm there at the time to do it. I need a solution that always works whether I'm there to intervene or not.
Since my DSL modem is not on the UPS, it would go down with everything else if the power fails. I set it up like that deliberately because I have an idea about how to solve this problem: I was thinking of writing a script that would ping google.com or some other high-traffic/high availability site. If the ping completes successfully, the server would keep running. If the ping fails (because the modem is off), the script would think the power is off and would tell the server to shut down. I would add the script to Cron and have it run every 5 minutes. That would hopefully give the server enough time to shut down before the UPS runs out of power.
Before I go to the trouble of writing the script, I would like to know if there is a better way to do what I need. Thanks in advance for any help.
15You should not ping an external site, but ping your DSL modem's IP. – LawrenceC – 2014-04-06T23:15:37.363
1@ultrasawblade...sounds like an answer, smells like an answer...it is an answer! – Pureferret – 2014-04-07T06:31:13.417
1As @ultrasawblade mentions, NEVER rely on outside sources for an internal setup. For example, if your internet suddenly fails, you lose connectivity and your server goes down. If Google.com decides to change their name for whatever reason, your server goes down. If you ping them using IP and that particular server farm goes down, your server goes down as well. this is the case with any outside source. Unless you are 100% sure that your server MUST ONLY be on when that other server is available, you don't want to rely on that other server for any reason. – Nzall – 2014-04-08T10:10:31.550
Do none of these answers work for you? – Dave – 2014-05-20T09:14:20.803