nut icon indicating copy to clipboard operation
nut copied to clipboard

NUT doesn't support "inhibitor interface"

Open Callisos opened this issue 4 years ago • 1 comments

I would like NUT to hibernate my PC instead of shutting it down when ONBATT event is registered. So I've put: SHUTDOWNCMD "systemctl hibernate" to /etc/ups/upsmon.conf.

But this works only once, unless there's a hack in /usr/lib/systemd/system-sleep/ which stops nut-server.service during hibernation and starts it during wake up, there also needs to be starting of nut-monitor.service specified. Otherwise nut-monitor.service reports to be "inactive (dead)" after waking up so no ONBATT event is registered and thus no hibernation takes place. In openSUSE's NUT package, currently there's a hack /usr/lib/systemd/system-sleep/nut.sh for it and is broken so it needs to be fixed manually.

After checking "man systemd-sleep", it states that scripts in /usr/lib/systemd/system-sleep/ are considered hacks for applications not using the so called "inhibitor interface".

If NUT would use inhibitor interface, there wouldn't be a need for /usr/lib/systemd/system-sleep/ hacks implemented by individual distros and my PC could be hibernated by NUT without problem.

Tested in OS: openSUSE Leap 15.3. with NUT v.2.7.4. Related mailing list discussion And continuation

Callisos avatar Aug 02 '21 22:08 Callisos

Seems related to #1833

jimklimov avatar Apr 06 '24 20:04 jimklimov

Some docs on this:

  • https://systemd.io/INHIBITOR_LOCKS/ and https://github.com/systemd/systemd/blob/main/docs/INHIBITOR_LOCKS.md - with its examples, the feature should actually not be hard to implement
  • https://stackoverflow.com/questions/78653343/how-to-get-an-inhibitor-lock-for-a-service-in-c-language - ...or not so fast? Gotta attach to D-Bus?
  • https://www.freedesktop.org/software/systemd/man/latest/systemd-inhibit.html

Posted some questions at https://github.com/systemd/systemd/issues/34004

jimklimov avatar Aug 15 '24 15:08 jimklimov

@Callisos : Cheers, FWIW, a PR with implementation attempt is posted, practical testing would be welcome :)

jimklimov avatar Aug 19 '24 16:08 jimklimov