My home server is connected to the UPS, but it is very simple - it hasn't data interface. So when the power had switched off my server can't figure it out unless UPS's battery is full. I have found a very simple solution, which helps safely shutdown my Linux box on power lost. All I need - plug the switch near the server directly into power socket. When the power is lost, switch turns off, so LAN card in the server, connected to the switch will be noticed about carrier lost. Every minute server checks link between switch and LAN card. In case it's lost, the server is turned down:

* * * * *  grep -q 0 /sys/class/net/eth0/carrier && /sbin/shutdown -h now

That's all. So simple, but very effective.


comments powered by Disqus