From dff80d589ec892b3a0c650781657641a5f8ddc65 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Mon, 19 Aug 2024 12:54:51 +0200 Subject: [PATCH 1/2] Introduce scripts/systemd/nut-sleep.service [#1833, #1070] Thanks to "Ropid" for contributing this file via https://github.com/networkupstools/nut/issues/1833#issuecomment-2292261061 Signed-off-by: Jim Klimov --- NEWS.adoc | 10 ++++++++++ scripts/systemd/Makefile.am | 5 +++-- scripts/systemd/nut-sleep.service | 26 ++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 scripts/systemd/nut-sleep.service diff --git a/NEWS.adoc b/NEWS.adoc index e231a099d8..8fd7f65841 100644 --- a/NEWS.adoc +++ b/NEWS.adoc @@ -158,6 +158,16 @@ https://github.com/networkupstools/nut/milestone/11 * added an `OBLBDURATION` (seconds) setting to optionally delay raising the alarm for immediate shutdown in critical situation. [#321] + - More systemd integration: + * Introduced a `nut-sleep.service` unit which stops `nut.target` when a + system sleep was requested, and starts it when the sleep is finished. + This helps avoid NUT shutting down a woken-up system just because its + power state was critical before the sleep (called as a `SHUTDOWNCMD` + implementation by the end-user), and a next-read timestamp was not seen + (deemed to be a stale UPS, meaning lost communications during critical + state, so must go down ASAP). While not as elegant as native systemd + "inhibitor interface" support, this approach does work. [#1833, #1070] + - gamatronic driver revised for safer memory operations; this was reported to have fixed a Segmentation Fault seen in earlier NUT releases with some of the devices supported by this driver. [#2427] diff --git a/scripts/systemd/Makefile.am b/scripts/systemd/Makefile.am index 9b19fcee54..38f2a05a2a 100644 --- a/scripts/systemd/Makefile.am +++ b/scripts/systemd/Makefile.am @@ -14,12 +14,13 @@ systemdsystemunit_DATA = \ nut-monitor.service \ nut-server.service \ nut-driver.target \ + nut-sleep.service \ nut.target systemdtmpfiles_DATA = \ nut-common-tmpfiles.conf -EXTRA_DIST += nut-driver.target nut.target +EXTRA_DIST += nut-driver.target nut.target nut-sleep.service systemdshutdown_SCRIPTS = nutshutdown @@ -29,7 +30,7 @@ sbin_SCRIPTS = ../upsdrvsvcctl/upsdrvsvcctl else EXTRA_DIST += \ - nut-driver@.service.in nut-monitor.service.in \ + nut-driver@.service.in nut-monitor.service.in nut-sleep.service \ nut-server.service.in nutshutdown.in nut-driver.target nut.target \ nut-driver-enumerator.path.in nut-driver-enumerator.service.in \ nut-driver-enumerator-daemon-activator.path.in \ diff --git a/scripts/systemd/nut-sleep.service b/scripts/systemd/nut-sleep.service new file mode 100644 index 0000000000..bb93c8c832 --- /dev/null +++ b/scripts/systemd/nut-sleep.service @@ -0,0 +1,26 @@ +# Network UPS Tools (NUT) systemd integration +# Copyright (C) 2011-2024 by NUT contirbutors +# Distributed under the terms of GPLv2+ +# See https://networkupstools.org/ +# and https://github.com/networkupstools/nut/ + +# A rather blunt solution for system sleeping support, for cases where +# we can not use a native libssytemd "inhibitor interface". This helps +# avoid NUT shutting down a woken-up system just because its power state +# was critical before the sleep, and a next-read timestamp was not seen +# (deemed to be a stale UPS, meaning lost comms during critical state, +# so must go down ASAP). + +[Unit] +Description=Network UPS Tools - sleep hook +Before=sleep.target +StopWhenUnneeded=yes + +[Service] +Type=oneshot +RemainAfterExit=yes +ExecStart=/usr/bin/systemctl stop nut.target +ExecStop=/usr/bin/systemctl start --no-block nut.target + +[Install] +WantedBy=sleep.target From f2514bb48c7c2b0ccf31f666be632f283b74f55a Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Mon, 19 Aug 2024 13:05:54 +0200 Subject: [PATCH 2/2] scripts/systemd/*: bump (C) to 2024 Signed-off-by: Jim Klimov --- .../systemd/nut-driver-enumerator-daemon-activator.service.in | 2 +- scripts/systemd/nut-driver-enumerator-daemon.service.in | 2 +- scripts/systemd/nut-driver-enumerator.path.in | 2 +- scripts/systemd/nut-driver-enumerator.service.in | 2 +- scripts/systemd/nut-driver.target | 2 +- scripts/systemd/nut-driver@.service.in | 2 +- scripts/systemd/nut-monitor.service.in | 2 +- scripts/systemd/nut-server.service.in | 2 +- scripts/systemd/nut.target | 2 +- scripts/systemd/nutshutdown.in | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/scripts/systemd/nut-driver-enumerator-daemon-activator.service.in b/scripts/systemd/nut-driver-enumerator-daemon-activator.service.in index c7af5be654..5e8eca32ff 100644 --- a/scripts/systemd/nut-driver-enumerator-daemon-activator.service.in +++ b/scripts/systemd/nut-driver-enumerator-daemon-activator.service.in @@ -1,5 +1,5 @@ # Network UPS Tools (NUT) systemd integration -# Copyright (C) 2011-2023 by NUT contirbutors +# Copyright (C) 2011-2024 by NUT contirbutors # Distributed under the terms of GPLv2+ # See https://networkupstools.org/ # and https://github.com/networkupstools/nut/ diff --git a/scripts/systemd/nut-driver-enumerator-daemon.service.in b/scripts/systemd/nut-driver-enumerator-daemon.service.in index af13ab4e29..8dacea7384 100644 --- a/scripts/systemd/nut-driver-enumerator-daemon.service.in +++ b/scripts/systemd/nut-driver-enumerator-daemon.service.in @@ -1,5 +1,5 @@ # Network UPS Tools (NUT) systemd integration -# Copyright (C) 2011-2023 by NUT contirbutors +# Copyright (C) 2011-2024 by NUT contirbutors # Distributed under the terms of GPLv2+ # See https://networkupstools.org/ # and https://github.com/networkupstools/nut/ diff --git a/scripts/systemd/nut-driver-enumerator.path.in b/scripts/systemd/nut-driver-enumerator.path.in index 09b9fdddb4..35878e051d 100644 --- a/scripts/systemd/nut-driver-enumerator.path.in +++ b/scripts/systemd/nut-driver-enumerator.path.in @@ -1,5 +1,5 @@ # Network UPS Tools (NUT) systemd integration -# Copyright (C) 2011-2023 by NUT contirbutors +# Copyright (C) 2011-2024 by NUT contirbutors # Distributed under the terms of GPLv2+ # See https://networkupstools.org/ # and https://github.com/networkupstools/nut/ diff --git a/scripts/systemd/nut-driver-enumerator.service.in b/scripts/systemd/nut-driver-enumerator.service.in index bab6feec95..067b149d92 100644 --- a/scripts/systemd/nut-driver-enumerator.service.in +++ b/scripts/systemd/nut-driver-enumerator.service.in @@ -1,5 +1,5 @@ # Network UPS Tools (NUT) systemd integration -# Copyright (C) 2011-2023 by NUT contirbutors +# Copyright (C) 2011-2024 by NUT contirbutors # Distributed under the terms of GPLv2+ # See https://networkupstools.org/ # and https://github.com/networkupstools/nut/ diff --git a/scripts/systemd/nut-driver.target b/scripts/systemd/nut-driver.target index 0055e469d4..95382674be 100644 --- a/scripts/systemd/nut-driver.target +++ b/scripts/systemd/nut-driver.target @@ -1,5 +1,5 @@ # Network UPS Tools (NUT) systemd integration -# Copyright (C) 2011-2023 by NUT contirbutors +# Copyright (C) 2011-2024 by NUT contirbutors # Distributed under the terms of GPLv2+ # See https://networkupstools.org/ # and https://github.com/networkupstools/nut/ diff --git a/scripts/systemd/nut-driver@.service.in b/scripts/systemd/nut-driver@.service.in index 1a1a04a4f0..7703cf0495 100644 --- a/scripts/systemd/nut-driver@.service.in +++ b/scripts/systemd/nut-driver@.service.in @@ -1,5 +1,5 @@ # Network UPS Tools (NUT) systemd integration -# Copyright (C) 2011-2023 by NUT contirbutors +# Copyright (C) 2011-2024 by NUT contirbutors # Distributed under the terms of GPLv2+ # See https://networkupstools.org/ # and https://github.com/networkupstools/nut/ diff --git a/scripts/systemd/nut-monitor.service.in b/scripts/systemd/nut-monitor.service.in index 25747fd30b..7b7316b4e1 100644 --- a/scripts/systemd/nut-monitor.service.in +++ b/scripts/systemd/nut-monitor.service.in @@ -1,5 +1,5 @@ # Network UPS Tools (NUT) systemd integration -# Copyright (C) 2011-2023 by NUT contirbutors +# Copyright (C) 2011-2024 by NUT contirbutors # Distributed under the terms of GPLv2+ # See https://networkupstools.org/ # and https://github.com/networkupstools/nut/ diff --git a/scripts/systemd/nut-server.service.in b/scripts/systemd/nut-server.service.in index c153c5d307..780a47beef 100644 --- a/scripts/systemd/nut-server.service.in +++ b/scripts/systemd/nut-server.service.in @@ -1,5 +1,5 @@ # Network UPS Tools (NUT) systemd integration -# Copyright (C) 2011-2023 by NUT contirbutors +# Copyright (C) 2011-2024 by NUT contirbutors # Distributed under the terms of GPLv2+ # See https://networkupstools.org/ # and https://github.com/networkupstools/nut/ diff --git a/scripts/systemd/nut.target b/scripts/systemd/nut.target index 3974fed4bf..b8dce11e71 100644 --- a/scripts/systemd/nut.target +++ b/scripts/systemd/nut.target @@ -1,5 +1,5 @@ # Network UPS Tools (NUT) systemd integration -# Copyright (C) 2011-2023 by NUT contirbutors +# Copyright (C) 2011-2024 by NUT contirbutors # Distributed under the terms of GPLv2+ # See https://networkupstools.org/ # and https://github.com/networkupstools/nut/ diff --git a/scripts/systemd/nutshutdown.in b/scripts/systemd/nutshutdown.in index 8625e167d9..f35d904bb3 100755 --- a/scripts/systemd/nutshutdown.in +++ b/scripts/systemd/nutshutdown.in @@ -8,7 +8,7 @@ # and their configuration files to be present locally and on still-mounted # filesystems (may be read-only). # -# Copyright (C) 2011-2023 by NUT contirbutors +# Copyright (C) 2011-2024 by NUT contirbutors # Michal Hlavinka, Laurent Bigonville, Arnaud Quette, Jim Klimov et al. # # See https://networkupstools.org/