Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 418177 - sys-power/apcupsd-3.14.8-r1: apcupsd.powerfail init script runlevel check fails when shutting down
Summary: sys-power/apcupsd-3.14.8-r1: apcupsd.powerfail init script runlevel check fai...
Status: UNCONFIRMED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal with 1 vote (vote)
Assignee: John Einar Reitan
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-05-29 20:19 UTC by parafin
Modified: 2018-05-01 07:57 UTC (History)
4 users (show)

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


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description parafin 2012-05-29 20:19:10 UTC
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 2.1.10.49 (default/linux/x86/10.0/desktop, gcc-4.5.3, glibc-2.14.1-r3, 3.3.3 i686)
=================================================================
                        System Settings
=================================================================
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]
app-shells/bash:          4.2_p20
dev-lang/python:          2.7.3-r1
dev-util/ccache:          3.1.6
dev-util/cmake:           2.8.7-r5
dev-util/pkgconfig:       0.26
sys-apps/baselayout:      2.1-r1
sys-apps/openrc:          0.9.8.4
sys-apps/sandbox:         2.5
sys-devel/autoconf:       2.13, 2.68
sys-devel/automake:       1.10.3, 1.11.1
sys-devel/binutils:       2.21.1-r1
sys-devel/gcc:            4.5.3-r2
sys-devel/gcc-config:     1.5-r2
sys-devel/libtool:        2.4-r1
sys-devel/make:           3.82-r1
sys-kernel/linux-headers: 3.1 (virtual/os-headers)
sys-libs/glibc:           2.14.1-r3
Repositories: gentoo local
ACCEPT_KEYWORDS="x86"
ACCEPT_LICENSE="*"
CBUILD="i686-pc-linux-gnu"
CFLAGS="-O2 -march=core2 -fomit-frame-pointer -ftracer -pipe"
CHOST="i686-pc-linux-gnu"
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"
DISTDIR="/data/distfiles"
EMERGE_DEFAULT_OPTS="--with-bdeps y"
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"
FFLAGS=""
GENTOO_MIRRORS="http://mirror.yandex.ru/gentoo-distfiles/"
LDFLAGS="-Wl,-O1 -Wl,--as-needed"
MAKEOPTS="-j3"
PKGDIR="/usr/portage/packages"
PORTAGE_CONFIGROOT="/"
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"
PORTAGE_TMPDIR="/usr/portage/local"
PORTDIR="/usr/portage"
PORTDIR_OVERLAY="/usr/local/portage"
SYNC="rsync://rsync.gentoo.org/gentoo-portage"
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

=================================================================
                        Package Settings
=================================================================

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"
Comment 1 parafin 2012-10-11 16:58:37 UTC
I have discovered another issue caused by absence of indefinite sleep in apcupsd.powerfail during power failure yesterday. This is what happened:
power failed;
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.
Comment 2 Matt Whitlock 2017-04-01 09:20:31 UTC
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.