systemd shutdown script missing, causing UPS killpower processing to be skipped

Bug #1603609 reported by bamyasi
44
This bug affects 8 people
Affects Status Importance Assigned to Milestone
nut (Ubuntu)
Fix Released
Undecided
Unassigned

Bug Description

Network UPS tools (NUT) on Ubuntu Server 16.04 LTS (x86_64) does not process loss of UPS battery power and forced system shutdown events due to lack of systemd-specific UPS shutdown script.

NUT uses initscripts for controlling its services. Ubuntu 16.04 uses systemd instead but has SysV initscripts compatibility packages installed by default. This works fine for normal system levels but not for level 0 (shutdown) which does NOT use /etc/init.d/halt script at all. However, NUT relies on this script for processing forced shutdown (FSD) events, e.g. the ones caused by the loss of mains power followed by UPS battery charge exhaustion: on a SysV initscripts system /etc/init.d/halt runs /etc/init.d/ups-monitor command which, in turn, checks for the presence of killpower flag and runs "nut-server poweroff" command in order to force programmed UPS load power cycling, if that flag was found.

Followed the instructions on this blog:

https://www.kepstin.ca/blog/networkupstoolsnutandsystemd/

Created file /lib/systemd/system-shutdown/nutshutdown with the following commands in it:

#!/bin/sh
/sbin/upsmon -K >/dev/null 2>&1 && /sbin/upsdrvctl shutdown

After that, NUT server would correctly process power loss events (both real and simulated) by cutting UPS power down after a system shutdown and restarting UPS after a short delay when/if the power is back.

$ uname -a
Linux xxx 4.4.0-31-generic #50-Ubuntu SMP Wed Jul 13 00:07:12 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

$ dpkg -l nut
ii nut 2.7.2-4ubuntu1 all network UPS tools - metapackage

Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in nut (Ubuntu):
status: New → Confirmed
Revision history for this message
Paul Annekov (paul.annekov) wrote :

@bamyasi thanks for your efforts. You saved my day.
I have found it's better to use more robust code for `nutshutdown` script, like in the official nut repo: https://github.com/networkupstools/nut/blob/master/scripts/systemd/nutshutdown.in. That code handles several issues like when ups doesn't turn off the load immediately (probably depends on "ups.delay.shutdown" value) or when it gets power during shutdown process and forgets about shutdown request.

Also 1 year has passed since bug report and this issue is still not fixed. I have checked zesty/artful releases and I don't see a shutdown script there too (https://packages.ubuntu.com/artful/amd64/nut-server/filelist), while I see it in a Debian package (https://packages.debian.org/jessie/amd64/nut-server/filelist) that was used as a base for Ubuntu ones. So load shutdown on low power should not work for all ubuntu 16.04+.

If I'm right, the latest merge was done by <email address hidden>. Maybe he can clarify this issue?

Revision history for this message
Christian Ehrhardt  (paelzer) wrote :

Hi,
this is part of the following Delta:
        - Disable systemd unit; it does not check nut.conf whether nut is
          configured, and thus fails to start (and the package install). The
          init.d script works well enough for the time being.

Which also causes the script this bug is related to not to be installed.

But the reasoning to disable holds no more true.
By default it starts and exits (as intended)

# systemctl status nut-server
● nut-server.service - Network UPS Tools - power devices information server
   Loaded: loaded (/lib/systemd/system/nut-server.service; enabled; vendor preset: enabled)
   Active: inactive (dead) since Wed 2017-11-15 15:36:40 UTC; 8min ago
    Tasks: 0 (limit: 4915)
   CGroup: /system.slice/nut-server.service

Nov 15 15:36:40 debian-buster systemd[1]: Starting Network UPS Tools - power devices information server...
Nov 15 15:36:40 debian-buster systemd[1]: Started Network UPS Tools - power devices information server.

If enabled in /etc/nut/nut.conf it works
# systemctl status nut-server
● nut-server.service - Network UPS Tools - power devices information server
   Loaded: loaded (/lib/systemd/system/nut-server.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Wed 2017-11-15 15:45:38 UTC; 2s ago
  Process: 18291 ExecStart=/sbin/upsd (code=exited, status=1/FAILURE)

Nov 15 15:45:38 debian-buster upsd[18291]: listening on 127.0.0.1 port 3493
Nov 15 15:45:38 debian-buster upsd[18291]: listening on ::1 port 3493
(I had no config, so the fail, but it works to consider the conf).

Revision history for this message
Christian Ehrhardt  (paelzer) wrote :
Revision history for this message
Christian Ehrhardt  (paelzer) wrote :

GOt an ack to the MP, uploading fix to Bionic

Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package nut - 2.7.4-5.1ubuntu2

---------------
nut (2.7.4-5.1ubuntu2) bionic; urgency=medium

  * Drop change which is no more needed, thereby fixes systemd integration
    and the availability of /lib/systemd/system-shutdown/nutshutdown
    (LP: #1603609)
    - Disable systemd unit; it does not check nut.conf whether nut is
      configured, and thus fails to start (and the package install). The
      init.d script works well enough for the time being.

nut (2.7.4-5.1ubuntu1) bionic; urgency=medium

  * Merge with Debian unstable. Remaining changes:
    - remove Build-Depends on libpowerman0-dev
    - remove nut-powerman-pdu
      + debian/nut-powerman-pdu.{install,manpages}: dropped for now
    - debian/nut-{cgi,server}.postinst: fix 'adduser' logic to be
      unconditional, since adduser is guaranteed to be idempotent.
    - debian/source_nut.py, debian/{nut,nut-server,nut-client}.install,
      debian/rules: Install apport hooks for all top-level nut packages.
    - Disable systemd unit; it does not check nut.conf whether nut is
      configured, and thus fails to start (and the package install). The
      init.d script works well enough for the time being.
    - debian/tests/test-nut.py: in the CVE_2012_2944 test, give nut at most
      + 5 seconds to shut down, instead of expecting it to be shut down
        immediately after sending the killall.
      + Additional indication on how to run tests for xenial+
    - debian/tests/control : Fix dep8 test failures:
       + Drop python-unit from dep8 dependencies since the python-test
         package has now been removed. The unittest module has shipped with
         Python since 2.1.
       + Add dep8 test dependency on python, since Python 2 is required and
         is not necessarily installed by default any more.
    - debian/libnutclient0.symbols: Correct symbols file for ppc64el.
    - fix cflags/ldflags mismatch (LP #1711092)
  * Drop:
    - udevd is called systemd-udevd (LP #1540008)
      [ Fixed in Debian 2.7.4-5.1 ]
    - d/libnutclient0.symbols: fix symbols in regard to gcc-7
      (LP #1711091)
      [ Fixed in Debian 2.7.4-5.1 ]

nut (2.7.4-5.1) unstable; urgency=medium

  * Non-maintainer upload.

  [ Laurent Bigonville ]
  * debian/nut-server.postinst: The udevd process is called systemd-udevd for
    quite sometimes already, properly detect whether it's running or not, this
    should fix the devices permissions for USB UPS's (LP: #1540008)
  * debian/rules: Mask ups-monitor, this is not a real LSB initscript but it's
    a symlink to the nut-client one. The purpose of this was to offer a common
    interface to shutdown the UPS in case of power loss, this is not necessary
    with systemd as this functionality is handeled by the
    /lib/systemd/system-shutdown/nutshutdown script now.

  [ Michael Stapelberg ]
  * Update symbols file for gcc-7 (Closes: #853579)

 -- Christian Ehrhardt <email address hidden> Wed, 15 Nov 2017 16:47:10 +0100

Changed in nut (Ubuntu):
status: Confirmed → Fix Released
Revision history for this message
Paul Annekov (paul.annekov) wrote :

@paelzer so your have fixed it for Ubuntu Bionic only? What about xenial/zesty?

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.