Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support sleep/hibernate integration (generally and with systemd in particular) #1833

Open
jimklimov opened this issue Jan 22, 2023 · 0 comments
Labels
documentation service/daemon start/stop General subject for starting and stopping NUT daemons (drivers, server, monitor); also BG/FG/Debug systemd
Milestone

Comments

@jimklimov
Copy link
Member

jimklimov commented Jan 22, 2023

There were several discussions in the past about NUT daemons emitting messages like "Data stale" when a system wakes up after prolonged sleep. One particular use-case is putting a system into hibernation when an UPS goes depleted, or into sleep when on-battery (hoping the lone RAM's power draw can be kept up for hours). This is not a platform-specific issue, everybody might do it, but it may have platform-specific optimal solutions (and/or general ones).

The messages make sense technically (lots of time passed since last poll) but seem confusing to some users and pollute the console cluttered by various subsystems after wake-up.

This issue is about exploring ways to integrate with service management frameworks like systemd to "know" a sleep happened, e.g. deal with dependencies on/against https://www.freedesktop.org/software/systemd/man/systemd-suspend.service.html family of units, or deliver hooks for them (example in https://blog.christophersmart.com/2016/05/11/running-scripts-before-and-after-suspend-with-systemd/ but official doc warns not to - deemed local hacks), or explore its "Inhibitor interface" per https://blog.christophersmart.com/2016/05/11/running-scripts-before-and-after-suspend-with-systemd/ and possibly something is possible by listening to systemd dbus...

With such integration, NUT daemons would know to silently reestablish connections when the system wakes up, and maybe chirp a message about that specifically. One solution could be to use the pre/post-sleep hooks to completely stop and start NUT services and so avoid "staleness" (also possibly account for IP address changes after wake-up).

A general-purpose alternative could be to somehow watch for system clock jumps (e.g. we have a 5 or 30 second pollfreq, and suddenly last loop took tens of minutes or more), and/or possibly track "local" time (as opposed to monotonous kernel clock) to see and react to NTP/RTC time jumps - which along with loops taking too long can be due to sleep or winter/summer time changes. Again, the purpose would be to tailor the reaction (and noise made) to this situation.

Also useful would be some documentation notes (FAQ?) and/or contributed scripts/* for different platforms, specifically about requesting sleep/hibernation as a SHUTDOWNCMD. Notably, such a command could take care of stopping/starting units and init-script styled services, and/or leaving flag-files for daemons to know about the intentional situation. (Service starts could be scheduled by cron/at facility, e.g. roughly at now + 1min generally).

Enthusiasts welcome to take on this, especially those who can test it well (have systems that do go to sleep while monitoring)!

@jimklimov jimklimov added systemd service/daemon start/stop General subject for starting and stopping NUT daemons (drivers, server, monitor); also BG/FG/Debug labels Jan 22, 2023
@jimklimov jimklimov added this to the 2.8.2 milestone Jan 22, 2023
@jimklimov jimklimov modified the milestones: 2.8.2, 2.8.3 Apr 4, 2024
@jimklimov jimklimov changed the title Support sleep/hibernate integration (generally and with systemd) Support sleep/hibernate integration (generally and with systemd in particular) Apr 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation service/daemon start/stop General subject for starting and stopping NUT daemons (drivers, server, monitor); also BG/FG/Debug systemd
Projects
None yet
Development

No branches or pull requests

1 participant