Skip to content

Commit

Permalink
Merge pull request networkupstools#2596 from jimklimov/issue-1070-unit
Browse files Browse the repository at this point in the history
Introduce `scripts/systemd/nut-sleep.service` unit
  • Loading branch information
jimklimov authored Aug 19, 2024
2 parents a682eae + f2514bb commit 575d423
Show file tree
Hide file tree
Showing 13 changed files with 49 additions and 12 deletions.
10 changes: 10 additions & 0 deletions NEWS.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
5 changes: 3 additions & 2 deletions scripts/systemd/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -29,7 +30,7 @@ sbin_SCRIPTS = ../upsdrvsvcctl/upsdrvsvcctl

else
EXTRA_DIST += \
[email protected] nut-monitor.service.in \
[email protected] 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 \
Expand Down
Original file line number Diff line number Diff line change
@@ -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/
Expand Down
2 changes: 1 addition & 1 deletion scripts/systemd/nut-driver-enumerator-daemon.service.in
Original file line number Diff line number Diff line change
@@ -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/
Expand Down
2 changes: 1 addition & 1 deletion scripts/systemd/nut-driver-enumerator.path.in
Original file line number Diff line number Diff line change
@@ -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/
Expand Down
2 changes: 1 addition & 1 deletion scripts/systemd/nut-driver-enumerator.service.in
Original file line number Diff line number Diff line change
@@ -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/
Expand Down
2 changes: 1 addition & 1 deletion scripts/systemd/nut-driver.target
Original file line number Diff line number Diff line change
@@ -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/
Expand Down
2 changes: 1 addition & 1 deletion scripts/systemd/[email protected]
Original file line number Diff line number Diff line change
@@ -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/
Expand Down
2 changes: 1 addition & 1 deletion scripts/systemd/nut-monitor.service.in
Original file line number Diff line number Diff line change
@@ -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/
Expand Down
2 changes: 1 addition & 1 deletion scripts/systemd/nut-server.service.in
Original file line number Diff line number Diff line change
@@ -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/
Expand Down
26 changes: 26 additions & 0 deletions scripts/systemd/nut-sleep.service
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion scripts/systemd/nut.target
Original file line number Diff line number Diff line change
@@ -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/
Expand Down
2 changes: 1 addition & 1 deletion scripts/systemd/nutshutdown.in
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down

0 comments on commit 575d423

Please sign in to comment.