From e946480a79f4a68b24410d83f6abfd50a2bcfd5c Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Mon, 20 Apr 2020 19:29:27 +0200 Subject: [PATCH 1/4] nut-driver-enumerator-daemon-activator.service.in : disable quick-start throttling --- .../nut-driver-enumerator-daemon-activator.service.in | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/scripts/systemd/nut-driver-enumerator-daemon-activator.service.in b/scripts/systemd/nut-driver-enumerator-daemon-activator.service.in index 86944fc3ff..e94fb197b2 100644 --- a/scripts/systemd/nut-driver-enumerator-daemon-activator.service.in +++ b/scripts/systemd/nut-driver-enumerator-daemon-activator.service.in @@ -26,6 +26,14 @@ Type=oneshot # Non-blocking systemd message posting should not take long, # or should be aborted and retried if it does (system bugs) TimeoutStartSec=10s +# If some process is writing the ups.conf file, it can be interpreted in +# some conditions by .path unit as many events requiring it to start - +# and eventually this gets throttled as a quickly started-restarted unit. +# While it should be permitted for manual start (likely .path trigger too) +# after interval expiration, this might race-condition to not detect some +# latest update into the configuration file if it happens after the main +# script loop has slurped intermediate state of device config. +StartLimitIntervalSec=0 ExecStart=/bin/systemctl reload-or-restart --no-block nut-driver-enumerator-daemon.service [Install] From 020441861e4d3e222575dbbc2e1d09b81a481848 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Sat, 2 Mar 2024 17:32:25 +0100 Subject: [PATCH 2/4] scripts/systemd/nut-server.service.in: summarize LimitNOFILE increase and ExecStartPost to monitor that it was applied, from FTY branch Originates from FTY commits: * 062d1868fa (Jim Klimov 2018-01-16 13:11:08 +0100) * 0e28cc865c (Jim Klimov 2018-01-16 13:37:39 +0100) * e9a67100a0 (Jim Klimov 2018-01-16 13:41:52 +0100) Signed-off-by: Jim Klimov --- scripts/systemd/nut-server.service.in | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/scripts/systemd/nut-server.service.in b/scripts/systemd/nut-server.service.in index 33f3b313d4..c153c5d307 100644 --- a/scripts/systemd/nut-server.service.in +++ b/scripts/systemd/nut-server.service.in @@ -26,6 +26,21 @@ Before=nut-monitor.service PartOf=nut.target [Service] +# A busy server can be monitoring a lot of devices as well as replying +# to many clients. The "infinity" definition is actually capped by OS +# settings and hardcoded defaults; typically can be 65535+ nowadays. +# On 64-bit distros this can well be set into hundreds of thousands +# as well (though note each connnection has a CPU and RAM overhead +# so one can strike physical limits upon deployment and/or bring the +# poorly sized system to a crawl, or worse). On a running system you +# can check /proc/$MAINPID/limits for active ulimits of the process. +# From my experiments, up to 1048576 can be set, but any larger value +# falls back to 65536. The systemd definition of "infinity" is 65536 +# too (or maybe it falls back to that); though this may be OS/distro +# limitation and not systemd fault specifically. +#LimitNOFILE=infinity +#LimitNOFILE=65535 +LimitNOFILE=1048576 EnvironmentFile=-@CONFPATH@/nut.conf SyslogIdentifier=%N # Note: foreground mode "-F" by default skips writing a PID file (and @@ -34,6 +49,7 @@ SyslogIdentifier=%N ExecStartPre=-@SYSTEMD_TMPFILES_PROGRAM@ --create @systemdtmpfilesdir@/nut-common-tmpfiles.conf ExecStart=@SBINDIR@/upsd @SYSTEMD_DAEMON_ARGS_UPSD@ ExecReload=@SBINDIR@/upsd -c reload -P $MAINPID +ExecStartPost=-/bin/grep -E 'Units|Max open files' /proc/${MAINPID}/limits # No tracking for PIDFile path and service attribute here (it might not # even exist). # If "-FF" or background-daemon mode is used, so that PID file exists From 360514e9067318ff4584edae97f76d30de84fa2d Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Wed, 29 Apr 2020 13:47:22 +0200 Subject: [PATCH 3/4] nut-driver-enumerator-daemon-activator.service : use older Service/StartLimitInterval for broader compatibility Should help avoid this warning and unachieved functionality on systemd-229 and older: * systemd[1]: [/lib/systemd/system/nut-driver-enumerator-daemon-activator.service:30] Unknown lvalue 'StartLimitIntervalSec' in section 'Service' --- .../nut-driver-enumerator-daemon-activator.service.in | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/systemd/nut-driver-enumerator-daemon-activator.service.in b/scripts/systemd/nut-driver-enumerator-daemon-activator.service.in index e94fb197b2..c7af5be654 100644 --- a/scripts/systemd/nut-driver-enumerator-daemon-activator.service.in +++ b/scripts/systemd/nut-driver-enumerator-daemon-activator.service.in @@ -33,7 +33,10 @@ TimeoutStartSec=10s # after interval expiration, this might race-condition to not detect some # latest update into the configuration file if it happens after the main # script loop has slurped intermediate state of device config. -StartLimitIntervalSec=0 +# Note: Using the older but still supported Service/StartLimitInterval +# see https://lists.freedesktop.org/archives/systemd-devel/2017-July/039255.html +# for broader compatibility. +StartLimitInterval=0 ExecStart=/bin/systemctl reload-or-restart --no-block nut-driver-enumerator-daemon.service [Install] From 0fbe658843f1b009fe629bbe1756393263b027a4 Mon Sep 17 00:00:00 2001 From: Jim Klimov Date: Sun, 3 Mar 2024 14:25:12 +0100 Subject: [PATCH 4/4] scripts/systemd/nut-driver-enumerator-daemon-activator.path.in: clarify the unit description (it does not strictly restart the daemon, can reload if running too) Signed-off-by: Jim Klimov --- .../systemd/nut-driver-enumerator-daemon-activator.path.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/systemd/nut-driver-enumerator-daemon-activator.path.in b/scripts/systemd/nut-driver-enumerator-daemon-activator.path.in index 615ce9fe57..02070bafba 100644 --- a/scripts/systemd/nut-driver-enumerator-daemon-activator.path.in +++ b/scripts/systemd/nut-driver-enumerator-daemon-activator.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/ @@ -8,7 +8,7 @@ # Trigger restart of nut-driver-enumerator-daemon-activator.service # whenever ups.conf is edited, which would cause reload-or-restart # of the nut-driver-enumerator-daemon.service for actual reconfig. -Description=Network UPS Tools - Trigger restart of nut-driver-enumerator-daemon.service whenever ups.conf is edited +Description=Network UPS Tools - Trigger reload-or-restart of nut-driver-enumerator-daemon.service whenever ups.conf is edited Conflicts=nut-driver-enumerator.service nut-driver-enumerator.path After=local-fs.target Before=nut-driver.target