12.2 powerdown: server shutdown but no UPS shutdown: Fixed

Background: When wall power fails a UPS unit will shut down a simple
desktop PC, and this is sufficient, but shutting down a server is more
complex. It must be shut down in such a way that when wall power
returns, the server is turned back on again* without human
intervention.*

The technique for doing this relies on

  1. a UPS unit which detects that wall power has come back and restarts the server.

  2. A server BIOS setting which turns on the server when power returns.

For this process to work, the UPS unit must receive a
delayed-UPS-shutdown signal which will put it into a state where it
will operate as in 1) above. A UPS unit which is simply left
“beeping” will not restart its load when wall power returns.

Problem: Up to release 12.1, the software in the NUT upsd package
handled this correctly, provided that it was correctly configured. In
12.2 this no longer happens. Even if NUT upsd is correctly
configured, the openSUSE script rcupsd->/etc/init.d/upsd does not shut
down the UPS unit. It should call NUT program “upsdrvctl shutdown”
but doesn’t. Looking at file /etc/sysconfig/shutdown,

# Hook during system shutdown to run extra command
HALT_POWERDOWN_INSERT="/etc/init.d/upsd try-powerdown"

it looks as if the intended sequence is “rcupsd try-powerdown” which
calls “rcupsd powerdown” which calls “upsdrvctl shutdown”. Currently
rcupsd attempts to call “try-powerdown”, but “try-powerdown” always
fails silently because $RUNLEVEL and $UPSD_POWERDOWN_CONDITION are
empty. /etc/init.d/upsd powerdown is never called.

In /etc/sysconfig/shutdown I specified

HALT_POWERDOWN_INSERT="/etc/init.d/upsd powerdown"

reran command SuSEconfig, and tried again but there was no change.
However typing the command /etc/init.d/upsd powerdown does shut down
the UPS unit.

Fix: There is a file /etc/init.d/halt.local which is currently empty:

  # /etc/init.d/halt.local
  # script with local commands to be executed from init on system shutdown
  # Here you should add things, that should happen directly before shuting
  # down.

I added the lines

  # 2012-10-28 Turn off the UPS unit. See http://rogerprice.org/NUT.html
  # Needed for automatic system restart when wall power returns.
  UPSDRVCTL_BIN=/usr/lib/ups/driver/upsdrvctl
  echo `date -I` `date +%T` "$0 calls $UPSDRVCTL_BIN shutdown" >> /var/log/halt.local
  $UPSDRVCTL_BIN shutdown

Test: I pulled the plug from the wall and witnessed a server shutdown
followed 10 seconds later by a UPS shutdown. Pushing the plug back
into the wall got the UPS and then the system running again.

Roger

halt.local is executed asynchronously with umount.target, so /var may not be available at this point, if it is separate filesystem.

Otherwise probably better place is /etc/systemd/system-shutdown. Everything in this directory is executed immediately before performing system halt, making delay more predictable.

On 2012-10-28 17:36, xiaoti wrote:

>
> Roger

Thanks! This is very nice.
What about writing a bugzilla, so that it is corrected in an update, if appropriate?


Cheers / Saludos,

Carlos E. R.
(from 11.4 x86_64 “Celadon” (Minas Tirith))

Hello.
I am interesting in /etc/systemd/system-shutdown.
I have a very small command to put in it (Nothing to do with UPS).
I need to copy a small config file of 1K.
But this directory does not exists on my system ( 12.2 )

Sorry, it is /lib/systemd/system-shutdown, my mistake.

Will you be willing to test update for NUT package that integrates it correctly with systemd?