Shutdown hosts remotely on power failure – A Christmas project!
The electricity network in my island is by far the worst in the entire planet. Seriously. In order to minimize the hardware failures, I bought two UPS units (Mustek & Trust). Sadly, the Trust one does not have a serial/usb port interface so I can’t control it in any way. Therefore, I came up with a neat solution. It would be cool to shutdown both computers when the battery of the Mustek UPS goes low. But how can I do that?
Legend:
Phoenix -> Host attached to Mustek UPS unit via usb
Mystical -> Host connected to Trust UPS but there is no usb/serial port to control it
Step 1: Install NUT on the Phoenix host
echo "sys-power/nut usb" >> /etc/portage/package.use/nut emerge -av nut
Step 2: Allow user on Mystical host to shutdown the host using sudo
Mystical ~ # grep -v ^# /etc/sudoers|grep -v '^$' root ALL=(ALL) ALL %wheel ALL=(ALL) ALL %users ALL= NOPASSWD: /sbin/shutdown -h now, /sbin/shutdown -r now
Step 3: Configure NUT
Nex@Phoenix ~ $ grep -v ^# /etc/nut/ups.conf
Nex@Phoenix ~ $ grep -v ^# /etc/nut/upsmon.conf
RUN_AS_USER Nex MONITOR mustek@localhost 1 server CHANGEME master MINSUPPLIES 1 SHUTDOWNCMD "ssh -l user -p XXXXX Mystical "sudo /sbin/shutdown -h now"
&& /sbin/shutdown -h +0"
POLLFREQ 5 POLLFREQALERT 5 HOSTSYNC 15 DEADTIME 15 POWERDOWNFLAG /etc/killpower RBWARNTIME 43200 NOCOMMWARNTIME 300 FINALDELAY 5










