I've added apcupsd.powerfail to shutdown runlevel and tried to test power failure situation. System did a normal shutdown, without killing UPS power. I've checked that /etc/apcupsd/powerfail file was created as it should - it wasn't the problem. Real problem was that "runlevel" command returns "unknown" when in shutdown runlevel, so this line from apcupsd.powerfail script fails:
if [ "$(runlevel | cut -d' ' -f2)" = "0" -a -f /etc/apcupsd/powerfail ]
I confirmed it by removing runlevel checking and redoing my test.
Also I like to point out, that even with this issue fixed, system continue with shutdown and turns the power off in the end. Originally (in baselayout-1) system waited for UPS to kill the power instead, so that system could automatically power itself up when the power comes back using "memory" function of BIOS. Now I have to set this BIOS setting to "always on" for everything to work as it should, which is IMHO a regression. May be there should be an indefinite sleep in apcupsd.powerfail script.
emerge --info apcupsd:
Portage 188.8.131.52 (default/linux/x86/10.0/desktop, gcc-4.5.3, glibc-2.14.1-r3, 3.3.3 i686)
System uname: Linux-3.3.3-i686-Intel-R-_Core-TM-2_CPU_6300_@_1.86GHz-with-gentoo-2.1
Timestamp of tree: Wed, 23 May 2012 16:00:01 +0000
distcc 3.1 i686-pc-linux-gnu [disabled]
ccache version 3.1.6 [enabled]
sys-devel/autoconf: 2.13, 2.68
sys-devel/automake: 1.10.3, 1.11.1
sys-kernel/linux-headers: 3.1 (virtual/os-headers)
Repositories: gentoo local
CFLAGS="-O2 -march=core2 -fomit-frame-pointer -ftracer -pipe"
CONFIG_PROTECT="/etc /usr/share/gnupg/qualified.txt /var/bind"
CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/env.d /etc/fonts/fonts.conf /etc/gconf /etc/gentoo-release /etc/revdep-rebuild /etc/sandbox.d /etc/terminfo"
CXXFLAGS="-O2 -march=core2 -fomit-frame-pointer -ftracer -pipe"
FEATURES="assume-digests binpkg-logs ccache distlocks ebuild-locks fixlafiles news parallel-fetch protect-owned sandbox sfperms strict unknown-features-warn unmerge-logs unmerge-orphans userfetch"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --compress --force --whole-file --delete --stats --human-readable --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages"
USE="X a52 aac adns alsa amr apache2 audiofile bash-completion berkdb bluray bzip2 cairo caps cddb cdparanoia cgi cracklib crypt css cups curl cxx dba dbus dri dts dvb dvd dvdr dvdread enca encode expat faac faad fbcon ffmpeg flac fontconfig foomaticdb ftp gcrypt gd gdbm geoip gif glib gmp gpm graphviz gtk iconv idn imap ipv6 ithreads jpeg jpeg2k kerberos lcms libsamplerate lzma lzo mad matroska milter mmx mmxext mng mp3 mpeg ncurses network nls nptl nsplugin offensive ogg opengl pam pcap pcre pdf perl pic png ppds pulseaudio python quicktime readline recode ruby sasl session sndfile speex spell sqlite sse sse2 sse3 ssl ssse3 svg tcpd theora threads threadsafe tiff truetype unicode usb vdpau vorbis vpx win32codecs x264 x86 xcb xml xpm xv xvid zlib" APACHE2_MODULES="alias auth_basic authn_file authz_host authz_user autoindex cgid dir info log_config mime mime_magic negotiation rewrite setenvif so speling status" ELIBC="glibc" INPUT_DEVICES="keyboard mouse void" KERNEL="linux" RUBY_TARGETS="ruby18" SANE_BACKENDS="plustek" USERLAND="GNU" VIDEO_CARDS="intel nvidia"
Unset: CPPFLAGS, CTARGET, INSTALL_MASK, LANG, LC_ALL, LINGUAS, PORTAGE_BUNZIP2_COMMAND, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS, USE_PYTHON
sys-power/apcupsd-3.14.8-r1 was built with the following:
USE="cgi nls usb -gnome -snmp"
CFLAGS="-O2 -march=core2 -fomit-frame-pointer -ftracer -pipe -fno-strict-aliasing"
CXXFLAGS="-O2 -march=core2 -fomit-frame-pointer -ftracer -pipe -fno-strict-aliasing"
I have discovered another issue caused by absence of indefinite sleep in apcupsd.powerfail during power failure yesterday. This is what happened:
battery charge level reached defined limit;
shutdown was initiated;
power returned before system was finished with shutdown cycle;
apcupsd.powerfail ran and sent killpower signal to UPS;
UPS switched to batteries and started timeout for cutting the power;
system shut down completely (did poweroff);
timeout was reached and UPS cut the power to the system for a couple of seconds, then returned to normal operation;
UPS did The Right Thing (c), but since system was shut down, capacitors in PSU held the voltage for those couple of seconds, so main board didn't notice that power was cut and didn't turn the system on after power returned.
So again, besides the broken runlevel check, apcupsd.powerfail must have indefinite (or very long) sleep after calling apcupsd --killpower - both for "return to previous power state" functionality in BIOS to work and to avoid problem I described in this comment.
I just experienced two power failures. On the first one, apcupsd correctly initiated system shutdown, but the apcupsd.powerfail script did not issue the killpower command to apcupsd. Mains power returned before the batteries ran all the way down, and so my system did not automatically power back up; I had to start it manually. Shortly later, the power went out again, but this time, apcupsd did issue the killpower command to the UPS, and everything behaved as it should. So there is some degree of non-determinism in whether the runlevel check succeeds.
I too have removed the runlevel check since the check for the existence of the powerfail file is sufficient.