[Nut-upsdev] RFC: nut and systemd

Stanislav Brabec sbrabec at suse.cz
Thu May 12 15:06:27 UTC 2011


Arnaud Quette :

> the shutoff (final ups poweroff) hook is located in the package's
> initscript, and is called from halt.
> whereas, in RH/Fedora, you don't have this generic role (afaik), nor
> the hook in the package's initscript.

SUSE has created HALT_POWERDOWN_INSERT in /etc/sysconfig/shutdown just
for the UPS needs. nut and apcupsd fills it during installation.

The SUSE init script has two special parameters:

powerdown: Instruct UPS to shutdown.

try-powerdown: Instruct UPS to shutdown, if halt is running or variable
UPSD_POWERDOWN_CONDITION is set and power is failing. Otherwise silently
quit.

Note: UPSD_POWERDOWN_CONDITION was created for
/usr/lib/pm-utils/sleep.d/99nut (hibernate on power outage support).


Yes, it is not very systematic, but it works. (Note that USB must be
working at that point and all needed libraries available.)

SUSE will probably migrate to systemd in the near future. I am not yet
familiar with systemd, but I think that the nature of systemd is a
system, where each service starts exactly one binary. I don't know,
whether systemd already supports a pre-powerdown target; if not, it
would be easy to add it there. Anyway, we should invent a different way
than "upsd powerdown" to issue powerdown with systemd.

Here are rough ideas, how nut can be integrated in a modern Linux distro
(i. e. system with udev+systemd+dbus):


1) Old init script connected to systemd. Powerdown connected to init
with an argument.

No change would be needed, but it is ugly and ineffective.


2) Three service files as mentioned in previous mail.

It seems like a nice solution, but it requires additional hacks at least
for distros that don't want to run nut as root (SUSE).

This solution would need a new way to call powerdown only when it is
really needed ((UPS supports power cycling and hardware is properly
configured to do it* && turning UPS off is requested && poweroff is
going to be called && power is failing) || (standalone workstation that
is configured to poweroff UPS every time (and always turn on after power
outage in BIOS))) - a small helper script or binary.


3) Two init scripts plus udev rules.

Migration of upsdrvctl to udev may be a logical solution. Udev can
handle permissions of device files.

There would be a downside in a bit more complicated configuration of
undetectable devices (e. g. serial UPSes). But in difference to HAL,
udev can do it. You can match a serial port and add nut-dedicated
attributes, e. g. NUT_DRIVER, and later udev can run helper for all
devices that contain NUT_DRIVER attribute.

This solution would again need a straight way to call powerdown only
when it is really needed.


4) Complete migration from init system (maybe except upsmon).

Drivers could be started by udev, nut clients can communicate over dbus,
nut server could be started on demand as dbus service.

This solution does not look smart for me:
- It needs heave rewrite.
- UPS daemon is not an on demand service by principle (even if no client
  is connected, daemon should react to power failure).
- Nobody uses the dbus over network yet.


5) Combined variant of 3 and 4 - udev starts drivers, drivers start
daemon if no daemon is running yet.

This solution seems to be overcomplicated.


Solution 3) is my favorite. (I wrote about it several years ago in the
age of hal, but hal never provided a working solution for serial.)

If you like the solution 3, I could try to create udev templates.



> Here are the packages on Suse (@Stan: nothing missing?)
> - nut (provided by either nut-classic or nut-hal iirc)
> - nut-cgi
For web servers.

> - nut-classic
This package will be renamed back to nut after disappearing of nut-hal.

> - nut-devel
> - nut-drivers-net
This was separated on request to limit size of minimal installations.

> - nut-hal
This package will disappear in future.

> - libupsclient1
Separate library conforms to Shared Library packaging Conventions.



(*) Correct and race-less power cycling support requires hardware that
can:

- Turn UPS down and poweron when power returns (and battery has enough
capacity to handle emergency shutdown for the next outage).

- Do a power cycling if power returns before UPS powerdown finishes.

- Prevent a race when computer initiates shutdown, and power returns
before powerdown is sent from computer to UPS. (Hardware can ignore such
request and reboot/resume might be needed instead.)


-- 
Best Regards / S pozdravem,

Stanislav Brabec
software developer
---------------------------------------------------------------------
SUSE LINUX, s. r. o.                          e-mail: sbrabec at suse.cz
Lihovarská 1060/12                            tel: +49 911 7405384547
190 00 Praha 9                                  fax: +420 284 028 951
Czech Republic                                    http://www.suse.cz/




More information about the Nut-upsdev mailing list