NUT doesn't support "inhibitor interface"
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
Seems related to #1833
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
@Callisos : Cheers, FWIW, a PR with implementation attempt is posted, practical testing would be welcome :)