Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 262234 - [PATCH] Power-kill handling for sys-power/apcupsd-3.14.5-r1
Summary: [PATCH] Power-kill handling for sys-power/apcupsd-3.14.5-r1
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: New packages (show other bugs)
Hardware: All Linux
: High enhancement (vote)
Assignee: Diego Elio Pettenò (RETIRED)
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-03-12 05:25 UTC by Matt Whitlock
Modified: 2009-03-22 16:15 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments
apcupsd-3.14.5-r1-powerfail.patch (apcupsd-3.14.5-r1-powerfail.patch,1.42 KB, patch)
2009-03-12 05:25 UTC, Matt Whitlock
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Matt Whitlock 2009-03-12 05:25:14 UTC
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).
Comment 1 Matt Whitlock 2009-03-12 05:25:44 UTC
Created attachment 184776 [details, diff]
apcupsd-3.14.5-r1-powerfail.patch
Comment 2 Diego Elio Pettenò (RETIRED) gentoo-dev 2009-03-20 14:09:47 UTC
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!
Comment 3 Diego Elio Pettenò (RETIRED) gentoo-dev 2009-03-22 13:58:27 UTC
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!
Comment 4 Matt Whitlock 2009-03-22 16:15:45 UTC
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