From the apcupsd manual <http://www.apcupsd.com/manual/Shutown_Sequenc_its_Discont.html>: "If apcupsd was properly installed, [the] halt script was modified to include a bit of new logic just before the final halt of the system. It first tests if the file /etc/apcupsd/powerfail exists, and if it does, it executes /etc/apcupsd/apccontrol killpower. It is this last step that will cause apcupsd to be re-executed with the --killpower option on the command line. This option tells apcupsd to inform the UPS to kill the power." This is critical so that the UPS does not continue to run and put unnecessary wear on its batteries after the host system has powered off. It is also necessary in order for the host system to power back on after mains power has been restored. The Gentoo base layout formerly handled the powerfail situation as described above, but in the migration to OpenRC the support was dropped. Fortunately, OpenRC now supports scripts in the "shutdown" runlevel, enabling this special powerfail handling to be installed modularly by the apcupsd ebuild. Attached to this bug report is a patch against the sys-power/apcupsd-3.14.5-r1 ebuild that adds a "powerfail" init script that implements the required logic. Additionally, the patch adds a notice to the ebuild's pkg_postinst() directing the user to add the "powerfail" script to the "shutdown" runlevel. I have tested the modified ebuild and the associated new "powerfail" init script on my own system, simulating a power failure by pulling the plug out of the wall, and I verify that the call to apcupsd was made at the appropriate time (after file systems had been remounted read/only).
Created attachment 184776 [details, diff] apcupsd-3.14.5-r1-powerfail.patch
I'll see to get this in today if I can, and certainly before Monday when I'm going to need this myself ;) Thanks Matt!
I've renamed the init script to apcupsd.powerfail but I've committed it now. I'll have to check how it would work with multiplexed init scripts though (I have two UPSes connected to this box). Thanks again!
Maybe there should be an /etc/conf.d/apcupsd.powerfail config file with a variable listing the apcupsd services on which to kill power. Then the powerfail script could iterate over them: #---/etc/conf.d/apcupsd.powerfail # Kill power on these instances, which correspond # to the config files in /etc/apcupsd/*.conf INSTANCES=( apcupsd ) #---/etc/init.d/apcupsd.powerfail ebegin 'Signaling UPSes to kill power' eindent for instance in "${INSTANCES[@]}" ; do ebegin "${instance}" /sbin/apcupsd -f "/etc/apcupsd/${instance}.conf" --killpower eend $? done eoutdent