I have got my hands on an APC UPS and some HP gen8 server, installed apcupsd on CentOS 7, connected the USB cable and everything was working fine except for this very annoying issue I had: * power goes down (pull the UPS power cord).

  • after some minutes the UPS battery threshold is triggered and the server shutdown procedure is launched by apcupsd.
  • power goes back up (plug in the power cord) while the server is already shutting down but the shutdown sequence is not yet completed.

RESULT: the server will not power itself up even if the correct setting is selected in BIOS (last power state or always on).
If the power stays offline for enough time for the server to completely shutdown and for the UPS to also shutdown once the power goes back online the server starts up automatically like it is supposed to do.
The only workaround I could think of to solve the issue is running a cron job on the router, which is running OpenWRT, to trigger wake-on-LAN for the server.
I don’t really like this solution, it feels hackish but still I could not find a better way to make the damn server power on automatically all by himself.
As for OpenWRT and wake-on-LAN, first of all install etherwake from LuCI or opkg:

$ opkg install etherwake

write a one line bash script containing the etherwake command and store it on an external USB drive attached to the router (or on the internal memory if possible):

cat wakeonlanServer.sh"
---
#!/bin/sh

# replace ff:ff:ff:ff:ff:ff with a wake-on-LAN enabled server NIC MAC address #
etherwake -b -i br-lan ff:ff:ff:ff:ff:ff

Enable and start OpenWRT cron daemon either via LuCI or command line:

$ /etc/init.d/cron enable
$ /etc/init.d/cron start

Last but not least, add a job to OpenWRT’s crontab file either via LuCI or command line:

$ crontab -e
* * * * * /bin/sh /mnt/usb/wakeupServer.sh