Skip to content

Commit bfcee3f

Browse files
authored
Merge pull request #2085 from jimklimov/systemd-comments
systemd integration update and nut.conf comments
2 parents 5ebc699 + 12f76f6 commit bfcee3f

15 files changed

Lines changed: 232 additions & 42 deletions

clients/Makefile.am

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,20 @@ $(top_builddir)/common/libcommonclient.la \
1212
$(top_builddir)/common/libparseconf.la: dummy
1313
@cd $(@D) && $(MAKE) $(AM_MAKEFLAGS) $(@F)
1414

15-
# by default, link programs in this directory with
16-
# the more compact libcommonclient.a bundle
17-
LDADD = $(top_builddir)/common/libcommonclient.la libupsclient.la $(NETLIBS)
15+
LDADD_FULL = $(top_builddir)/common/libcommon.la libupsclient.la $(NETLIBS)
16+
if WITH_SSL
17+
LDADD_FULL += $(LIBSSL_LIBS)
18+
endif
19+
20+
LDADD_CLIENT = $(top_builddir)/common/libcommonclient.la libupsclient.la $(NETLIBS)
1821
if WITH_SSL
19-
LDADD += $(LIBSSL_LIBS)
22+
LDADD_CLIENT += $(LIBSSL_LIBS)
2023
endif
2124

25+
# by default, link programs in this directory with
26+
# the more compact libcommonclient.a bundle
27+
LDADD = $(LDADD_CLIENT)
28+
2229
# Avoid per-target CFLAGS, because this will prevent re-use of object
2330
# files. In any case, CFLAGS are only -I options, so there is no harm,
2431
# but only add them if we really use the target.
@@ -62,12 +69,13 @@ upscmd_SOURCES = upscmd.c upsclient.h
6269
upsrw_SOURCES = upsrw.c upsclient.h
6370
upslog_SOURCES = upslog.c upsclient.h upslog.h
6471
upsmon_SOURCES = upsmon.c upsmon.h upsclient.h
72+
upsmon_LDADD = $(LDADD_FULL)
6573
if HAVE_WINDOWS_SOCKETS
6674
message_SOURCES = message.c
6775
endif
6876

6977
upssched_SOURCES = upssched.c upssched.h
70-
upssched_LDADD = $(top_builddir)/common/libcommon.la $(top_builddir)/common/libparseconf.la $(NETLIBS)
78+
upssched_LDADD = $(top_builddir)/common/libcommonclient.la $(top_builddir)/common/libparseconf.la $(NETLIBS)
7179

7280
upsimage_cgi_SOURCES = upsimage.c upsclient.h upsimagearg.h cgilib.c cgilib.h
7381
upsimage_cgi_LDADD = $(LDADD) $(LIBGD_LDFLAGS)

common/common.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -832,14 +832,14 @@ int upsnotify(upsnotify_state_t state, const char *fmt, ...)
832832
NUT_UNUSED_VARIABLE(buf);
833833
NUT_UNUSED_VARIABLE(msglen);
834834
if (!upsnotify_reported_disabled_systemd)
835-
upsdebugx(6, "%s: notify about state %i with libsystemd: "
835+
upsdebugx(0, "%s: notify about state %i with libsystemd: "
836836
"skipped for libcommonclient build, "
837837
"will not spam more about it", __func__, state);
838838
upsnotify_reported_disabled_systemd = 1;
839839
# else
840840
if (!getenv("NOTIFY_SOCKET")) {
841841
if (!upsnotify_reported_disabled_systemd)
842-
upsdebugx(6, "%s: notify about state %i with libsystemd: "
842+
upsdebugx(0, "%s: notify about state %i with libsystemd: "
843843
"was requested, but not running as a service unit now, "
844844
"will not spam more about it",
845845
__func__, state);
@@ -1110,7 +1110,7 @@ int upsnotify(upsnotify_state_t state, const char *fmt, ...)
11101110
) {
11111111
if (ret == -127) {
11121112
if (!upsnotify_reported_disabled_notech)
1113-
upsdebugx(6, "%s: failed to notify about state %i: no notification tech defined, will not spam more about it", __func__, state);
1113+
upsdebugx(0, "%s: failed to notify about state %i: no notification tech defined, will not spam more about it", __func__, state);
11141114
upsnotify_reported_disabled_notech = 1;
11151115
} else {
11161116
upsdebugx(6, "%s: failed to notify about state %i", __func__, state);
@@ -1120,7 +1120,7 @@ int upsnotify(upsnotify_state_t state, const char *fmt, ...)
11201120
#if defined(WITH_LIBSYSTEMD) && (WITH_LIBSYSTEMD)
11211121
# if ! DEBUG_SYSTEMD_WATCHDOG
11221122
if (state == NOTIFY_STATE_WATCHDOG && !upsnotify_reported_watchdog_systemd) {
1123-
upsdebugx(6, "%s: logged the systemd watchdog situation once, will not spam more about it", __func__);
1123+
upsdebugx(0, "%s: logged the systemd watchdog situation once, will not spam more about it", __func__);
11241124
upsnotify_reported_watchdog_systemd = 1;
11251125
}
11261126
# endif

conf/nut.conf.sample

Lines changed: 54 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,33 @@
11
# Network UPS Tools: example nut.conf
22
#
3+
# This file tries to standardize the various files being found in the field,
4+
# like /etc/default/nut on Debian based systems, /etc/sysconfig/ups on RedHat
5+
# based systems, ... Distribution's init script or service unit/method script
6+
# should source this file to see which component(s) has to be started.
7+
# Some scripts and units provided by NUT project itself may also look into
8+
# this file for optional configuration about OS integration.
9+
#
10+
# IMPORTANT NOTES:
11+
# This file is intended to be sourced by standard POSIX shell scripts
12+
# (so there is no guaranteed `export VAR=VAL` syntax) and additionally
13+
# by systemd on Linux (no guaranteed expansion of variables).
14+
# You MUST NOT use spaces around the equal sign!
15+
# Practical support for this file and its settings currently varies between
16+
# various OS packages and NUT sample scripts, but should converge over time.
17+
#
18+
# See also: `man nut.conf` (usually in Manual pages Section 5,
19+
# for Configuration files)
20+
#
321
##############################################################################
422
# General section
523
##############################################################################
624
# The MODE determines which part of the NUT is to be started, and which
725
# configuration files must be modified.
826
#
9-
# This file try to standardize the various files being found in the field, like
10-
# /etc/default/nut on Debian based systems, /etc/sysconfig/ups on RedHat based
11-
# systems, ... Distribution's init script should source this file to see which
12-
# component(s) has to be started.
13-
#
1427
# The values of MODE can be:
1528
# - none: NUT is not configured, or use the Integrated Power Management, or use
16-
# some external system to startup NUT components. So nothing is to be started.
29+
# some external system to startup NUT components. So nothing is to be started
30+
# by scripts or services bundled with NUT packages.
1731
# - standalone: This mode address a local only configuration, with 1 UPS
1832
# protecting the local system. This implies to start the 3 NUT layers (driver,
1933
# upsd and upsmon) and the matching configuration files. This mode can also
@@ -23,17 +37,42 @@
2337
# specific LISTEN directive in upsd.conf.
2438
# Since this MODE is opened to the network, a special care should be applied
2539
# to security concerns.
26-
# - netclient: this mode only requires upsmon.
27-
#
28-
# IMPORTANT NOTE:
29-
# This file is intended to be sourced by standard POSIX shell scripts (so
30-
# there is no guaranteed `export VAR=VAL` syntax) and by systemd on Linux.
31-
# You MUST NOT use spaces around the equal sign!
40+
# - netclient: this mode only requires upsmon (and tools it may be using, like
41+
# upssched or custom scripts) to monitor a remote NUT server and possibly
42+
# shut down this system (part of upsmon must run as root then).
3243

3344
MODE=none
3445

35-
# Uncomment this to allow starting the service even if ups.conf has no device
36-
# sections at the moment. This environment variable overrides the built-in
37-
# "false" and an optional same-named default flag that can be set in upsd.conf:
46+
# Uncomment this to allow starting the service even if `ups.conf` has no device
47+
# sections configured at the moment. This environment variable overrides the
48+
# built-in "false" flag in `upsd`, and an optional same-named default flag that
49+
# can be set in `upsd.conf`. If you want a data server always running, even if
50+
# it initially has nothing to serve (may be live-reloaded later, when devices
51+
# become configured), this option is for you.
3852
#ALLOW_NO_DEVICE=true
3953
#export ALLOW_NO_DEVICE
54+
55+
# The optional 'UPSD_OPTIONS' allow to set upsd specific command-line options.
56+
# It is ignored when 'MODE' above indicates that no upsd should be running.
57+
# It may be redundant in comparison to options which can be set in `upsd.conf`.
58+
#UPSD_OPTIONS=
59+
60+
# The optional 'UPSMON_OPTIONS' allow to set upsmon specific command-line options.
61+
# It is ignored when 'MODE' above indicates that no upsmon should be running.
62+
# It may be redundant in comparison to options which can be set in `upsmon.conf`.
63+
#UPSMON_OPTIONS=
64+
65+
# If the optional 'POWEROFF_WAIT' is configured (to a value that can be handled
66+
# by `/bin/sleep` on the current system - typically an integer with the number
67+
# of seconds for a delay, but not always limited to that syntax), and the current
68+
# system which manages one or more UPS devices would not only command it to shut
69+
# down, but also try to avoid the "Power race". Caveats emptor, see NUT FAQ and
70+
# other docs for details.
71+
#POWEROFF_WAIT=3600
72+
73+
# The optional 'POWEROFF_QUIET' setting controls if the NUT shutdown integration
74+
# scripts or service units would emit messages about their activity (or lack
75+
# thereof). By default they may be verbose, to aid post-mortem troubleshooting
76+
# via logs or console captures.
77+
# Set to `true` to avoid that trove of information, if you consider it noise.
78+
#POWEROFF_QUIET=true

configure.ac

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4352,6 +4352,11 @@ dnl by "root:${RUN_AS_GROUP}" with 77x permissions. Is it safer?..
43524352
AS_IF([test -n "$systemdtmpfilesdir"],
43534353
[mkdir -p "${TOP_BUILDDIR}"/scripts/systemd
43544354
cat > "${TOP_BUILDDIR}"/scripts/systemd/nut-common-tmpfiles.conf.in << EOF
4355+
# Network UPS Tools (NUT) systemd integration
4356+
# Distributed under the terms of GPLv2+
4357+
# See https://networkupstools.org/
4358+
# and https://github.com/networkupstools/nut/
4359+
43554360
# See also: https://github.com/networkupstools/nut/wiki/Technicalities:-Work-with-PID-and-state-file-paths#pidpath-altpidpath-statepath
43564361
# State file (e.g. upsd to driver pipes) and PID file location for NUT:
43574362
d @STATEPATH@ 0770 @RUN_AS_USER@ @RUN_AS_GROUP@ - -

docs/configure.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,17 @@ configuration, this can include the `libupsclient`, `libnutclient`,
631631
`libnutclientsub`, `libnutscan` and their pkg-config metadata (see
632632
`--with-pkgconfig-dir` option). The default is `<exec_prefix>/lib`.
633633

634+
--libexecdir=PATH
635+
636+
Sets the installation path for "executable libraries" -- helper scripts
637+
or programs that are not intended for direct and regular use by people,
638+
and rather are implementation details of services. Depending on the
639+
build configuration, this can include the `nut-driver-enumerator.sh`,
640+
`sockdebug`, and others. The default is `<exec_prefix>/libexec`.
641+
642+
Package distributions may want to use this option to customize this path
643+
to include the package name, e.g. set it to `<exec_prefix>/libexec/nut`.
644+
634645
--with-pkgconfig-dir=PATH
635646

636647
Where to install pkg-config `*.pc` files. This option only has an

docs/man/nut.conf.txt

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,17 @@ netclient;; When only upsmon is required, possibly because
5454
there are other hosts that are more closely attached to the UPS,
5555
the MODE should be set to netclient.
5656

57+
*ALLOW_NO_DEVICE*::
58+
Optional, defaults to `false`. Set this to `true` to allow starting the `upsd`
59+
NUT data server service even if `ups.conf` has no device sections configured
60+
at the moment. This environment variable overrides the built-in "false" flag
61+
value in the `upsd` program, and an optional same-named default flag that
62+
can be set in `upsd.conf`.
63+
+
64+
If you want a data server always running and responding on the network, even
65+
if it initially has nothing to serve (may be live-reloaded later, when devices
66+
become configured), this option is for you.
67+
5768
*UPSD_OPTIONS*::
5869
Optional. Set upsd specific options. See linkman:upsd[8] for more
5970
details. It is ignored when 'MODE' above indicates that no upsd
@@ -76,10 +87,17 @@ unavailable. On the other hand, it should not be so long that the
7687
system remains offline for an unreasonable amount of time if line
7788
power has returned. See sleep(1) for compatible time syntax.
7889
If you specify the time in seconds, use the "s" suffix.
79-
90+
+
8091
WARNING: this workaround might be dangerous under some circumstances.
8192
Please read http://bugs.debian.org/358696 for more details.
8293

94+
*POWEROFF_QUIET*::
95+
Optional, defaults to `false`. This setting controls if the NUT shutdown
96+
integration scripts or service units would emit messages about their activity
97+
(or lack thereof). By default they may be verbose, to aid in post-mortem
98+
troubleshooting via logs or console captures. Set to `true` to avoid that
99+
trove of information, if you consider it noise.
100+
83101
EXAMPLE
84102
-------
85103

docs/nut.dict

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
personal_ws-1.1 en 3241 utf-8
1+
personal_ws-1.1 en 3243 utf-8
22
AAS
33
ABI
44
ACFAIL
@@ -2224,6 +2224,7 @@ libcurl
22242224
libdir
22252225
libdummy
22262226
libexec
2227+
libexecdir
22272228
libfreeipmi
22282229
libgd
22292230
libgpgme
@@ -2395,6 +2396,7 @@ monpasswd
23952396
monslave
23962397
monuser
23972398
morbo
2399+
mortem
23982400
mozilla
23992401
mqtt
24002402
msec

scripts/systemd/nut-driver-enumerator.path.in

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
# Trigger restart of nut-driver-enumerator.service whenever ups.conf is edited
2+
# Network UPS Tools (NUT) systemd integration
3+
# Copyright (C) 2011-2023 by NUT contirbutors
4+
# Distributed under the terms of GPLv2+
5+
# See https://networkupstools.org/
6+
# and https://github.com/networkupstools/nut/
27

38
[Path]
49
PathModified=@CONFPATH@/ups.conf

scripts/systemd/nut-driver-enumerator.service.in

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# Network UPS Tools (NUT) systemd integration
2+
# Copyright (C) 2011-2023 by NUT contirbutors
3+
# Distributed under the terms of GPLv2+
4+
# See https://networkupstools.org/
5+
# and https://github.com/networkupstools/nut/
6+
17
[Unit]
28
# This unit starts early in system lifecycle to set up nut-driver instances.
39
# End-user may also restart this unit after editing ups.conf to automatically

scripts/systemd/nut-driver.target

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# Network UPS Tools (NUT) systemd integration
2+
# Copyright (C) 2011-2023 by NUT contirbutors
3+
# Distributed under the terms of GPLv2+
4+
# See https://networkupstools.org/
5+
# and https://github.com/networkupstools/nut/
6+
17
[Unit]
28
Description=Network UPS Tools - target for power device drivers on this system
39
After=local-fs.target

0 commit comments

Comments
 (0)