Package: nut Version: 2.0.3-4 Severity: important Tags: patch When the init script's "poweroff" command is called from /etc/init.d/halt (via "ups-monitor poweroff"): If the UPS does not cut power immediately, control will return to the halt script, which will subsequently power off the system.
This can happen in a number of scenarios: the driver fails to transmit the shutdown command, the UPS waits for a short while before actually cutting the power (offdelay), line power returns and the UPS can't/won't cut power, etc. Of course, having the system switch itself off is bad, because then it will not automatically turn back on when supplied with power again (assuming the reasonable BIOS default of "On/Off state: Last state"). I am attaching a proposed patch that yields a better behavior, and follows the advice given in the NUT docs (shutdown.txt): The "poweroff" command invokes "upsdrvctl shutdown", and then whether or not that succeeds, it waits for a configurable length of time (15 minutes seems like a good default), and reboots. I made some minor changes to the terminal output, too, taking into account e.g. the large blurb of text produced by the upsdrvctl invocation. P.S.: I think it would be helpful to add a note to nut's README.Debian file reminding the user that the HALT variable (in /etc/default/halt) must be set to "poweroff" in order for /etc/init.d/halt to invoke /etc/init.d/ups-monitor, when using the default SHUTDOWNCMD of "shutdown -h +0". I had set "HALT=halt", thinking that this was what I wanted, but changed it back after examining the halt script. P.S.2: The nut init script contains an instance of / \t/....
diff -ru nut-2.0.3/debian/nut.default nut-2.0.3-patched/debian/nut.default --- nut-2.0.3/debian/nut.default 2006-03-22 12:35:44.000000000 -0500 +++ nut-2.0.3-patched/debian/nut.default 2006-03-23 13:23:07.000000000 -0500 @@ -3,3 +3,18 @@ # start upsmon START_UPSMON=no + +# At the end of an emergency system halt, the upsmon master will signal the +# UPS to switch off. This may fail for any number of reasons, however, most +# notably if line power returns during the shutdown process. (See the +# section "Power races" in /usr/share/doc/nut/docs/shutdown.txt.gz) +# +# The system will wait this long for the UPS to cut power, and then reboot. +# It should be long enough to exhaust the batteries (in case line power +# continues to be unavailable), but not so long that the system remains +# offline for an unreasonable amount of time (if line power has returned). +# +# See the sleep(1) man page for compatible time syntax. If you specify the +# time in seconds, use the "s" suffix. +# +POWEROFF_WAIT=15m diff -ru nut-2.0.3/debian/nut.init nut-2.0.3-patched/debian/nut.init --- nut-2.0.3/debian/nut.init 2006-03-22 12:35:44.000000000 -0500 +++ nut-2.0.3-patched/debian/nut.init 2006-03-23 13:50:18.095529658 -0500 @@ -102,9 +102,17 @@ if [ -f "$flag" ] ; then if /sbin/upsmon -K >/dev/null 2>&1 ; then echo "Shutting down the UPS ..." - sleep 5 - ! /sbin/upsdrvctl shutdown && echo -n " FAILED" - echo "." + sleep 1 + if /sbin/upsdrvctl shutdown ; then + sleep 5 + echo -n "Waiting for UPS to cut the power" + else + echo "Shutdown failed." + echo -n "Waiting for UPS batteries to run down" + fi + echo " (will reboot after $POWEROFF_WAIT) ..." + sleep "$POWEROFF_WAIT" + /etc/init.d/reboot else echo "Power down flag is not set (UPS shutdown not needed)" fi