Skip to content

Commit a8c9b0f

Browse files
authored
Merge pull request networkupstools#2891 from jimklimov/issue-2638
Introduce `nut-udev-settle.service` for systemd integration
2 parents 991d398 + 4001cf4 commit a8c9b0f

File tree

9 files changed

+86
-12
lines changed

9 files changed

+86
-12
lines changed

Makefile.am

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,6 +1111,7 @@ install-as-root:
11111111
@SYSTEMD_SYSTEMCTL_PROGRAM@ stop nut-monitor.service nut-server.service || true ; \
11121112
@SYSTEMD_SYSTEMCTL_PROGRAM@ stop nut-driver.service || true ; \
11131113
@SYSTEMD_SYSTEMCTL_PROGRAM@ stop nut-driver.target || true ; \
1114+
@SYSTEMD_SYSTEMCTL_PROGRAM@ stop nut-udev-settle.service || true ; \
11141115
@SYSTEMD_SYSTEMCTL_PROGRAM@ stop nut.target || true ; \
11151116
fi ; \
11161117
if $(WITH_SOLARIS_SMF) || $(WITH_SOLARIS_INIT) ; then \
@@ -1222,8 +1223,8 @@ install-as-root:
12221223
@SYSTEMD_SYSTEMCTL_PROGRAM@ preset-all || exit ; \
12231224
else \
12241225
echo "$@: Apply systemd enabled/disabled service defaults" >&2 ; \
1225-
@SYSTEMD_SYSTEMCTL_PROGRAM@ disable nut.target nut-driver.target nut-monitor nut-server nut-driver-enumerator.path nut-driver-enumerator.service || exit ; \
1226-
@SYSTEMD_SYSTEMCTL_PROGRAM@ enable nut.target nut-driver.target nut-monitor nut-server nut-driver-enumerator.path nut-driver-enumerator.service || exit ; \
1226+
@SYSTEMD_SYSTEMCTL_PROGRAM@ disable nut.target nut-driver.target nut-udev-settle.service nut-monitor nut-server nut-driver-enumerator.path nut-driver-enumerator.service || exit ; \
1227+
@SYSTEMD_SYSTEMCTL_PROGRAM@ enable nut.target nut-driver.target nut-udev-settle.service nut-monitor nut-server nut-driver-enumerator.path nut-driver-enumerator.service || exit ; \
12271228
fi ; \
12281229
echo "$@: Reconfigure nut-driver-enumerator (service instance wrapping)" >&2 ; \
12291230
@SYSTEMD_SYSTEMCTL_PROGRAM@ restart udev && applied_udev=true || true ; \

NEWS.adoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,9 @@ This requirement compromises usability of `make distcheck` on platforms without
476476
suspending the `upsmon` process, etc. [#2597]
477477
* Introduced delivery of default systemd presets (lists of enabled/disabled
478478
units). [#2721]
479+
* A `nut-udev-settle.service` was introduced to replace dependency on the
480+
`systemd-udev-settle.service` which is deprecated and causes warnings on
481+
some systems. It was shown to benefit NUT use-cases however. [#2638]
479482

480483
- gamatronic driver revised for safer memory operations; this was reported
481484
to have fixed a Segmentation Fault seen in earlier NUT releases with

UPGRADING.adoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ Changes from 2.8.2 to 2.8.3
4848
disable certain NUT units by default; its comments document each choice.
4949
[issue #2721]
5050
51+
- A `nut-udev-settle.service` was introduced to replace dependency on the
52+
`systemd-udev-settle.service` which is deprecated and causes warnings on
53+
some systems. It was shown to benefit NUT use-cases however. [#2638]
54+
5155
- Reference packages prepared by `make package` should now separate the
5256
`PACKAGE_VERSION` from the platform-dependent prefix by a dash character
5357
in the ultimate package file name. Previously they were glued together

scripts/python/Makefile.am

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,23 @@ NUT_MONITOR_COMMON_TEMPLATE = \
9292
install-data-hook-app-locale-symlinks:
9393
@cd "$(DESTDIR)$(nutmonitordir)/app/locale" && \
9494
for L in fr it ru ; do \
95-
$(LN_S) "$$L".po "$$L"/"$$L"_"`echo "$$L" | tr '[a-z]' '[A-Z]'`".UTF-8.po || exit ; \
96-
$(LN_S) "$$L" "$$L"_"`echo "$$L" | tr '[a-z]' '[A-Z]'`".UTF-8 || exit ; \
95+
UTF8_NAME="$$L"_"`echo "$$L" | tr '[a-z]' '[A-Z]'`".UTF-8 || exit ; \
96+
UTF8_POFILE="$${L}/$${UTF8_NAME}.po" || exit ; \
97+
UTF8_SUBDIR="$${UTF8_NAME}" || exit ; \
98+
rm -f "$${UTF8_POFILE}" || true ; rm -f "$${UTF8_SUBDIR}" || true ; \
99+
$(LN_S) "$$L".po "$${UTF8_POFILE}" || exit ; \
100+
$(LN_S) "$$L" "$${UTF8_SUBDIR}" || exit ; \
97101
done
98102

99103
uninstall-hook-app-locale-symlinks:
100104
@RES=0 ; \
101105
cd "$(DESTDIR)$(nutmonitordir)/app/locale" && \
102106
for L in fr it ru ; do \
103-
rm -f "$$L"/"$$L"_"`echo "$$L" | tr '[a-z]' '[A-Z]'`".UTF-8.po || RES=$$? ; \
104-
rm -f "$$L"_"`echo "$$L" | tr '[a-z]' '[A-Z]'`".UTF-8 || RES=$$? ; \
107+
UTF8_NAME="$$L"_"`echo "$$L" | tr '[a-z]' '[A-Z]'`".UTF-8 || exit ; \
108+
UTF8_POFILE="$${L}/$${UTF8_NAME}.po" || exit ; \
109+
UTF8_SUBDIR="$${UTF8_NAME}" || exit ; \
110+
rm -f "$${UTF8_POFILE}" || RES=$$? ; \
111+
rm -f "$${UTF8_SUBDIR}" || RES=$$? ; \
105112
done ; \
106113
exit $$RES
107114

scripts/systemd/Makefile.am

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ systemdsystemunit_DATA = \
1515
nut-monitor.service \
1616
nut-server.service \
1717
nut-driver.target \
18+
nut-udev-settle.service \
1819
nut.target
1920

2021
if !WITH_LIBSYSTEMD_INHIBITOR
@@ -29,7 +30,7 @@ systemdsystempreset_DATA = \
2930
nut-systemd.preset
3031

3132
# Add files not generated from .in templates
32-
EXTRA_DIST += nut-sleep.service nut-systemd.preset
33+
EXTRA_DIST += nut-sleep.service nut-systemd.preset nut-udev-settle.service
3334

3435
systemdshutdown_SCRIPTS = nutshutdown
3536

@@ -41,7 +42,7 @@ else !HAVE_SYSTEMD
4142
EXTRA_DIST += \
4243
nut.target.in nut-systemd.preset \
4344
nut-driver@.service.in nut-driver.target.in \
44-
nut-server.service.in \
45+
nut-server.service.in nut-udev-settle.service \
4546
nut-logger.service.in nut-monitor.service.in \
4647
nut-sleep.service nutshutdown.in \
4748
nut-driver-enumerator.path.in nut-driver-enumerator.service.in \

scripts/systemd/nut-server.service.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ Documentation=@NUT_WEBSITE_BASE@/docs/man/nut.conf.html
3939
[Service]
4040
# A busy server can be monitoring a lot of devices as well as replying
4141
# to many clients. The "infinity" definition is actually capped by OS
42-
# settings and hardcoded defaults; typically can be 65535+ nowadays.
42+
# settings and hard-coded defaults; typically can be 65535+ nowadays.
4343
# On 64-bit distros this can well be set into hundreds of thousands
44-
# as well (though note each connnection has a CPU and RAM overhead
44+
# as well (though note each connection has a CPU and RAM overhead
4545
# so one can strike physical limits upon deployment and/or bring the
4646
# poorly sized system to a crawl, or worse). On a running system you
4747
# can check /proc/$MAINPID/limits for active ulimits of the process.

scripts/systemd/nut-systemd.preset

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ enable nut-driver.target
3939
# I don't think a template can be activated/deactivated; anyhow
4040
# this is NDE's bread and butter at run-time:
4141
#enable nut-driver@.service
42+
# The nut-udev-settle.service would be used by USB/Serial/... drivers
43+
# wrapped by NDE, and so referenced there if needed. It should not
44+
# auto-start if not used by any driver:
45+
enable nut-udev-settle.service
4246

4347
# Activate the "upsd" data server, to represent drivers on the network.
4448
# Requires "ups.conf", "upsd.conf", "upsd.users":
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Network UPS Tools (NUT) systemd integration
2+
# Copyright (C) 2025- by NUT contributors
3+
# Distributed under the terms of GPLv2+
4+
# See https://networkupstools.org/
5+
# and https://github.com/networkupstools/nut/
6+
#
7+
# This file was adapted from systemd-udev-settle.service provided as part of
8+
# systemd. The original service is no longer recommended for general use in
9+
# recent distributions (does not guarantee reliable detection, and delays
10+
# system readiness for log-in), but waiting for udev to settle its currently
11+
# running operations has proven useful in some cases for NUT practice.
12+
#
13+
# Original file's terms:
14+
#
15+
# SPDX-License-Identifier: LGPL-2.1-or-later
16+
#
17+
# This file is part of systemd.
18+
#
19+
# systemd is free software; you can redistribute it and/or modify it
20+
# under the terms of the GNU Lesser General Public License as published by
21+
# the Free Software Foundation; either version 2.1 of the License, or
22+
# (at your option) any later version.
23+
24+
# This service can dynamically be pulled-in by legacy services which
25+
# cannot reliably cope with dynamic device configurations, and wrongfully
26+
# expect a populated /dev during bootup.
27+
28+
[Unit]
29+
Description=Wait for udev To Complete Device Initialization before USB-capable NUT drivers start
30+
Documentation=man:systemd-udev-settle.service(8)
31+
DefaultDependencies=no
32+
Wants=systemd-udevd.service
33+
After=systemd-udev-trigger.service
34+
ConditionPathIsReadWrite=/sys
35+
36+
# Used when/if requested by specific nut-driver@.service instances.
37+
# No auto-start or dependency otherwise.
38+
39+
[Service]
40+
Type=oneshot
41+
TimeoutSec=180
42+
# We want to re-trigger this service during NUT driver restarts
43+
# (maybe several at once) as we reconnect after e.g. USB bus reset,
44+
# for changes in USB/Serial/... devices that may need permissions
45+
# for NUT to be applied. So we do not want it to remain "active".
46+
#RemainAfterExit=yes
47+
ExecStart=udevadm settle

scripts/upsdrvsvcctl/nut-driver-enumerator.sh.in

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,11 @@ fi
109109
### Also can tune whether a driver "Wants" another service (would consider
110110
### ordering if that one is enabled, but live if it is disabled), or if it
111111
### "Requires" that (would cause that to start).
112-
DEPSVC_USB_SYSTEMD="systemd-udev.service systemd-udev-settle.service"
112+
DEPSVC_USB_SYSTEMD="systemd-udevd.service nut-udev-settle.service"
113113
DEPREQ_USB_SYSTEMD="Wants"
114+
# Serial drivers may rely on USB dongles or even custom-owned real ports:
115+
DEPSVC_SERIAL_SYSTEMD="systemd-udevd.service nut-udev-settle.service"
116+
DEPREQ_SERIAL_SYSTEMD="Wants"
114117
DEPSVC_NET_FULL_SYSTEMD="network-online.target systemd-resolved.service ifplugd.service"
115118
DEPREQ_NET_FULL_SYSTEMD="Wants"
116119
DEPSVC_NET_LOCAL_SYSTEMD="network.target"
@@ -644,6 +647,7 @@ upsconf_getDriverMedia() {
644647
printf '%s\n%s\n' "$CURR_DRV" "" ; return ;;
645648
esac
646649
;;
650+
# FIXME: other modbus? sysfs like INA219? GPIO? Other local devices?
647651
*) printf '%s\n%s\n' "$CURR_DRV" "" ; return ;;
648652
esac
649653
}
@@ -949,8 +953,11 @@ systemd_registerInstance() {
949953
network)
950954
DEPSVC="$DEPSVC_NET_FULL_SYSTEMD"
951955
DEPREQ="$DEPREQ_NET_FULL_SYSTEMD" ;;
952-
serial) ;;
956+
serial)
957+
DEPSVC="$DEPSVC_SERIAL_SYSTEMD"
958+
DEPREQ="$DEPREQ_SERIAL_SYSTEMD" ;;
953959
'') ;;
960+
# FIXME: modbus? sysfs like INA219? GPIO? Other local devices?
954961
*) echo "WARNING: Unexpected NUT media type ignored: '${_MED}'" >&2 ;;
955962
esac
956963
if [ -n "$DEPSVC" ]; then

0 commit comments

Comments
 (0)