Skip to content

Commit 99ea972

Browse files
authored
Merge pull request #2746 from jimklimov/issue-1803
Introduce service wrapping for `upslog` client daemon, and `nut-systemd.preset` file
2 parents 5d832b9 + ea480a5 commit 99ea972

28 files changed

+506
-34
lines changed

Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ DISTCHECK_VALGRIND_FLAGS = --with-all=auto --with-ssl=auto --with-doc=skip --wit
7676
# Note: this rule uses envvar DISTCHECK_FLAGS expanded at run-time
7777
DISTCHECK_CONFIGURE_FLAGS = ${DISTCHECK_FLAGS} \
7878
--with-systemdsystemunitdir='$${prefix}/lib/systemd/system' \
79+
--with-systemdsystempresetdir='$${prefix}/usr/lib/systemd/system-preset' \
7980
--with-systemdshutdowndir='$${prefix}/lib/systemd/system-shutdown' \
8081
--with-systemdtmpfilesdir='$${prefix}/usr/lib/tmpfiles.d' \
8182
--with-augeas-lenses-dir='$${prefix}/usr/share/augeas/lenses' \

NEWS.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,8 @@ https://github.com/networkupstools/nut/milestone/11
329329
should be handled similar (avoid stale UPS data and rash decisions)
330330
for summer/winter time change on non-UTC deployments, a debugger
331331
suspending the `upsmon` process, etc. [#2597]
332+
* Introduced delivery of default systemd presets (lists of enabled/disabled
333+
units). [#2721]
332334
333335
- gamatronic driver revised for safer memory operations; this was reported
334336
to have fixed a Segmentation Fault seen in earlier NUT releases with

UPGRADING.adoc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ Changes from 2.8.2 to 2.8.3
4444
Please use it, it immensely helps with community troubleshooting!
4545
[issue #1949]
4646
47+
- When packaging or custom-building for (Linux) distributions with systemd,
48+
you can now take advantage of `nut-systemd.preset` file to enable or
49+
disable certain NUT units by default; its comments document each choice.
50+
[issue #2721]
51+
4752
- Reference packages prepared by `make package` should now separate the
4853
`PACKAGE_VERSION` from the platform-dependent prefix by a dash character
4954
in the ultimate package file name. Previously they were glued together

clients/upslog.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,15 @@ static void help(const char *prog)
157157
printf(" -F - stay foregrounded even if logging into a file\n");
158158
printf(" -B - stay backgrounded even if logging to stdout\n");
159159
printf(" -p <pidbase> - Base name for PID file (defaults to \"%s\")\n", prog);
160+
printf(" - NOTE: PID file is written regardless of fore/back-grounding\n");
160161
printf(" -s <ups> - Monitor UPS <ups> - <upsname>@<host>[:<port>]\n");
161162
printf(" - Example: -s myups@server\n");
162163
printf(" -m <tuple> - Monitor UPS <ups,logfile>\n");
163164
printf(" - Example: -m myups@server,/var/log/myups.log\n");
165+
printf(" - NOTE: You can use '-' as logfile for stdout\n");
166+
printf(" and it would not imply foregrounding\n");
167+
printf(" - NOTE: '-s ups' and/or '-l file' options are ignored\n");
168+
printf(" if tuples are used, but you can specify many tuples\n");
164169
printf(" -u <user> - Switch to <user> if started as root\n");
165170
printf(" -V - Display the version of this software\n");
166171
printf(" -h - Display this help text\n");

configure.ac

Lines changed: 91 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3997,11 +3997,17 @@ AC_ARG_WITH([systemdsystemunitdir],
39973997
case "${systemdsystemunitdir}" in
39983998
yes|auto|"")
39993999
AS_IF([test x"$have_PKG_CONFIG" = xyes],
4000-
[systemdsystemunitdir="`$PKG_CONFIG --variable=systemdsystemunitdir systemd 2>/dev/null`" && test -n "$systemdsystemunitdir" || systemdsystemunitdir="`$PKG_CONFIG --variable=systemdsystemunitdir libsystemd 2>/dev/null`"],
4001-
[AS_IF([test "${systemdsystemunitdir}" = yes],
4000+
[def_systemdsystemunitdir="`$PKG_CONFIG --variable=systemdsystemunitdir systemd 2>/dev/null`" && test -n "$def_systemdsystemunitdir" || \
4001+
def_systemdsystemunitdir="`$PKG_CONFIG --variable=systemdsystemunitdir libsystemd 2>/dev/null`" || def_systemdsystemunitdir=""],
4002+
[def_systemdsystemunitdir=""])
4003+
4004+
AS_IF([test x"${def_systemdsystemunitdir}" = x], [
4005+
AS_IF([test "${systemdsystemunitdir}" = yes],
40024006
[AC_MSG_ERROR([--with-systemdsystemunitdir=${systemdsystemunitdir} was requested, but PKG_CONFIG could not be queried for the system settings])])
4003-
systemdsystemunitdir=""
4004-
])
4007+
systemdsystemunitdir=""
4008+
], [systemdsystemunitdir="${def_systemdsystemunitdir}"])
4009+
4010+
unset def_systemdsystemunitdir
40054011
;;
40064012
no)
40074013
systemdsystemunitdir=""
@@ -4029,6 +4035,48 @@ dnl This option is only provided so that make distcheck can override it,
40294035
dnl otherwise we ask pkg-config whenever --with-systemdsystemunitdir is
40304036
dnl given
40314037

4038+
dnl Similarly for presets (list of svcs enabled/disabled by default)
4039+
AC_MSG_CHECKING(whether to install systemd preset files)
4040+
AC_ARG_WITH([systemdsystempresetdir],
4041+
[AS_HELP_STRING([--with-systemdsystempresetdir=DIR], [Directory for systemd preset files (auto)])],
4042+
[systemdsystempresetdir="${withval}"],
4043+
[systemdsystempresetdir="auto"])
4044+
4045+
dnl Note: this option is enabled only if systemdsystemunitdir is not trivial
4046+
if test -n "${systemdsystemunitdir}"; then
4047+
case "${systemdsystempresetdir}" in
4048+
yes|auto|"")
4049+
AS_IF([test x"$have_PKG_CONFIG" = xyes],
4050+
[def_systemdsystempresetdir="`$PKG_CONFIG --variable=systemdsystempresetdir systemd 2>/dev/null`" && test -n "$def_systemdsystempresetdir" || \
4051+
def_systemdsystempresetdir="`$PKG_CONFIG --variable=systemdsystempresetdir libsystemd 2>/dev/null`" || def_systemdsystempresetdir=""],
4052+
[def_systemdsystempresetdir=""])
4053+
4054+
AS_IF([test x"${def_systemdsystempresetdir}" = x], [
4055+
AS_IF([test "${systemdsystempresetdir}" = yes],
4056+
[AC_MSG_ERROR([--with-systemdsystempresetdir=${systemdsystempresetdir} was requested, but PKG_CONFIG could not be queried for the system settings])])
4057+
systemdsystempresetdir=""
4058+
], [systemdsystempresetdir="${def_systemdsystempresetdir}"])
4059+
4060+
unset def_systemdsystempresetdir
4061+
;;
4062+
no)
4063+
systemdsystempresetdir=""
4064+
;;
4065+
*)
4066+
AS_IF([test -d "${systemdsystempresetdir}"], [],
4067+
[AC_MSG_WARN([--with-systemdsystempresetdir='${systemdsystempresetdir}' was requested, but that location does not currently exist in build environment - just so you know...])])
4068+
;;
4069+
esac
4070+
fi
4071+
if test "${systemdsystempresetdir}" = "auto" ; then systemdsystempresetdir=""; fi
4072+
if test -n "${systemdsystempresetdir}"; then
4073+
AC_MSG_RESULT(using ${systemdsystempresetdir})
4074+
NUT_REPORT_PATH_INTEGRATIONS([Service unit presets for systemd], [${systemdsystempresetdir}])
4075+
else
4076+
AC_MSG_RESULT(no)
4077+
fi
4078+
4079+
dnl Similarly for shutdown integration hooks
40324080
AC_MSG_CHECKING(whether to install systemd shutdown files)
40334081
AC_ARG_WITH([systemdshutdowndir],
40344082
AS_HELP_STRING([--with-systemdshutdowndir=DIR], [Directory for systemd shutdown scripts (auto)]),
@@ -4039,11 +4087,17 @@ if test -n "${systemdsystemunitdir}"; then
40394087
case "${systemdshutdowndir}" in
40404088
yes|auto|"")
40414089
AS_IF([test x"$have_PKG_CONFIG" = xyes],
4042-
[systemdshutdowndir="`$PKG_CONFIG --variable=systemdshutdowndir systemd 2>/dev/null`" && test -n "$systemdshutdowndir" || systemdshutdowndir="`$PKG_CONFIG --variable=systemdshutdowndir libsystemd 2>/dev/null`"],
4043-
[AS_IF([test "${systemdshutdowndir}" = yes],
4090+
[def_systemdshutdowndir="`$PKG_CONFIG --variable=systemdshutdowndir systemd 2>/dev/null`" && test -n "$def_systemdshutdowndir" || \
4091+
def_systemdshutdowndir="`$PKG_CONFIG --variable=systemdshutdowndir libsystemd 2>/dev/null`" || def_systemdshutdowndir=""],
4092+
[def_systemdshutdowndir=""])
4093+
4094+
AS_IF([test x"${def_systemdshutdowndir}" = x], [
4095+
AS_IF([test "${systemdshutdowndir}" = yes],
40444096
[AC_MSG_ERROR([--with-systemdshutdowndir=${systemdshutdowndir} was requested, but PKG_CONFIG could not be queried for the system settings])])
4045-
systemdshutdowndir=""
4046-
])
4097+
systemdshutdowndir=""
4098+
], [systemdshutdowndir="${def_systemdshutdowndir}"])
4099+
4100+
unset def_systemdshutdowndir
40474101
;;
40484102
no)
40494103
systemdshutdowndir=""
@@ -4072,11 +4126,17 @@ AC_ARG_WITH([systemdtmpfilesdir],
40724126
case "${systemdtmpfilesdir}" in
40734127
yes|auto|"")
40744128
AS_IF([test x"$have_PKG_CONFIG" = xyes],
4075-
[systemdtmpfilesdir="`$PKG_CONFIG --variable=tmpfilesdir systemd 2>/dev/null`" && test -n "$systemdtmpfilesdir" || systemdtmpfilesdir="`$PKG_CONFIG --variable=tmpfilesdir libsystemd 2>/dev/null`"],
4076-
[AS_IF([test "${systemdtmpfilesdir}" = yes],
4129+
[def_systemdtmpfilesdir="`$PKG_CONFIG --variable=tmpfilesdir systemd 2>/dev/null`" && test -n "$def_systemdtmpfilesdir" || \
4130+
def_systemdtmpfilesdir="`$PKG_CONFIG --variable=tmpfilesdir libsystemd 2>/dev/null`" || def_systemdtmpfilesdir=""],
4131+
[def_systemdtmpfilesdir=""])
4132+
4133+
AS_IF([test x"${def_systemdtmpfilesdir}" = x], [
4134+
AS_IF([test "${systemdtmpfilesdir}" = yes],
40774135
[AC_MSG_ERROR([--with-systemdtmpfilesdir=${systemdtmpfilesdir} was requested, but PKG_CONFIG could not be queried for the system settings])])
4078-
systemdtmpfilesdir=""
4079-
])
4136+
systemdtmpfilesdir=""
4137+
], [systemdtmpfilesdir="${def_systemdtmpfilesdir}"])
4138+
4139+
unset def_systemdtmpfilesdir
40804140
;;
40814141
no)
40824142
systemdtmpfilesdir=""
@@ -4167,6 +4227,8 @@ AS_IF([test x"${with_libsystemd}" = xyes && test x"${SYSTEMD_SUPPORTS_DAEMON_TYP
41674227
dnl needed for `upsd -c reload` in legacy scripts and old habits to work:
41684228
SYSTEMD_DAEMON_ARGS_UPSD="-FF"
41694229
SYSTEMD_DAEMON_TYPE_UPSD="notify"
4230+
SYSTEMD_DAEMON_ARGS_UPSLOG="-F"
4231+
SYSTEMD_DAEMON_TYPE_UPSLOG="notify"
41704232
SYSTEMD_DAEMON_ARGS_UPSMON="-F"
41714233
SYSTEMD_DAEMON_TYPE_UPSMON="notify"
41724234
SYSTEMD_DAEMON_ARGS_DRIVER="-FF"
@@ -4183,29 +4245,36 @@ AS_IF([test x"${with_libsystemd}" = xyes && test x"${SYSTEMD_SUPPORTS_DAEMON_TYP
41834245
SYSTEMD_DAEMON_NOTIFYACCESS_DRIVER="NotifyAccess=all"
41844246
dnl Similar for UPSMON with its two processes:
41854247
SYSTEMD_DAEMON_NOTIFYACCESS_UPSMON="NotifyAccess=all"
4186-
dnl UPSD is started directly by systemd and do not fork:
4248+
dnl UPSD is started directly by systemd and does not fork:
41874249
SYSTEMD_DAEMON_NOTIFYACCESS_UPSD="NotifyAccess=main"
4250+
dnl Similarly for upslog (per settings above):
4251+
SYSTEMD_DAEMON_NOTIFYACCESS_UPSLOG="NotifyAccess=main"
41884252
dnl Note: at this time we do not pre-define watchdog settings,
41894253
dnl to avoid breaking something by a poorly hardcoded guess.
41904254
dnl This is something end-users should do for their deployment,
41914255
dnl especially for drivers
41924256
SYSTEMD_DAEMON_WATCHDOG_DRIVER="#WatchdogSec=240s"
41934257
SYSTEMD_DAEMON_WATCHDOG_UPSD="#WatchdogSec=240s"
4258+
SYSTEMD_DAEMON_WATCHDOG_UPSLOG="#WatchdogSec=240s"
41944259
SYSTEMD_DAEMON_WATCHDOG_UPSMON="#WatchdogSec=240s"
41954260
], [
41964261
dnl "Usual" daemons that happen to be spawned by systemd
41974262
SYSTEMD_DAEMON_ARGS_UPSD="-F"
41984263
SYSTEMD_DAEMON_TYPE_UPSD="simple"
4264+
SYSTEMD_DAEMON_ARGS_UPSLOG="-F"
4265+
SYSTEMD_DAEMON_TYPE_UPSLOG="simple"
41994266
SYSTEMD_DAEMON_ARGS_UPSMON="-F"
42004267
SYSTEMD_DAEMON_TYPE_UPSMON="simple"
42014268
SYSTEMD_DAEMON_ARGS_DRIVER=""
42024269
SYSTEMD_DAEMON_TYPE_DRIVER="forking"
42034270
SYSTEMD_DAEMON_NOTIFYACCESS_DRIVER=""
42044271
SYSTEMD_DAEMON_NOTIFYACCESS_UPSD=""
4272+
SYSTEMD_DAEMON_NOTIFYACCESS_UPSLOG=""
42054273
SYSTEMD_DAEMON_NOTIFYACCESS_UPSMON=""
42064274
dnl Watchdog should not be configured for not-notifying units, right?
42074275
SYSTEMD_DAEMON_WATCHDOG_DRIVER="#WatchdogSec=240s"
42084276
SYSTEMD_DAEMON_WATCHDOG_UPSD="#WatchdogSec=240s"
4277+
SYSTEMD_DAEMON_WATCHDOG_UPSLOG="#WatchdogSec=240s"
42094278
SYSTEMD_DAEMON_WATCHDOG_UPSMON="#WatchdogSec=240s"
42104279
])
42114280

@@ -4924,14 +4993,18 @@ AC_SUBST(LIBSYSTEMD_CFLAGS)
49244993
AC_SUBST(LIBSYSTEMD_LIBS)
49254994
AC_SUBST(SYSTEMD_DAEMON_ARGS_UPSD)
49264995
AC_SUBST(SYSTEMD_DAEMON_TYPE_UPSD)
4996+
AC_SUBST(SYSTEMD_DAEMON_ARGS_UPSLOG)
4997+
AC_SUBST(SYSTEMD_DAEMON_TYPE_UPSLOG)
49274998
AC_SUBST(SYSTEMD_DAEMON_ARGS_UPSMON)
49284999
AC_SUBST(SYSTEMD_DAEMON_TYPE_UPSMON)
49295000
AC_SUBST(SYSTEMD_DAEMON_ARGS_DRIVER)
49305001
AC_SUBST(SYSTEMD_DAEMON_TYPE_DRIVER)
49315002
AC_SUBST(SYSTEMD_DAEMON_NOTIFYACCESS_DRIVER)
49325003
AC_SUBST(SYSTEMD_DAEMON_NOTIFYACCESS_UPSD)
5004+
AC_SUBST(SYSTEMD_DAEMON_NOTIFYACCESS_UPSLOG)
49335005
AC_SUBST(SYSTEMD_DAEMON_NOTIFYACCESS_UPSMON)
49345006
AC_SUBST(SYSTEMD_DAEMON_WATCHDOG_UPSD)
5007+
AC_SUBST(SYSTEMD_DAEMON_WATCHDOG_UPSLOG)
49355008
AC_SUBST(SYSTEMD_DAEMON_WATCHDOG_UPSMON)
49365009
AC_SUBST(SYSTEMD_DAEMON_WATCHDOG_DRIVER)
49375010
AC_SUBST(SYSTEMD_TMPFILES_PROGRAM)
@@ -4972,6 +5045,7 @@ AC_SUBST(htmldocdir)
49725045
AC_SUBST(htmlmandir)
49735046
AC_SUBST(pkgconfigdir)
49745047
AC_SUBST(systemdsystemunitdir)
5048+
AC_SUBST(systemdsystempresetdir)
49755049
AC_SUBST(systemdshutdowndir)
49765050
AC_SUBST(systemdtmpfilesdir)
49775051
AC_SUBST(auglensdir)
@@ -5592,7 +5666,9 @@ AC_CONFIG_FILES([
55925666
scripts/systemd/Makefile
55935667
scripts/systemd/nut.target
55945668
scripts/systemd/nut-common-tmpfiles.conf
5669+
scripts/systemd/nut-driver.target
55955670
scripts/systemd/nut-driver@.service
5671+
scripts/systemd/nut-logger.service
55965672
scripts/systemd/nut-monitor.service
55975673
scripts/systemd/nut-server.service
55985674
scripts/systemd/nut-driver-enumerator.service
@@ -5602,6 +5678,7 @@ AC_CONFIG_FILES([
56025678
scripts/systemd/nut-driver-enumerator-daemon-activator.path
56035679
scripts/Solaris/nut-driver-enumerator.xml
56045680
scripts/Solaris/nut-driver.xml
5681+
scripts/Solaris/nut-logger.xml
56055682
scripts/Solaris/nut-monitor.xml
56065683
scripts/Solaris/nut-server.xml
56075684
scripts/Solaris/nut.xml
@@ -5638,6 +5715,7 @@ m4_foreach_w([SCRIPTFILE], [
56385715
scripts/upsdrvsvcctl/upsdrvsvcctl
56395716
scripts/systemd/nutshutdown
56405717
scripts/Solaris/svc-nut-server
5718+
scripts/Solaris/svc-nut-logger
56415719
scripts/Solaris/svc-nut-monitor
56425720
scripts/Solaris/precheck.py
56435721
scripts/Solaris/preinstall

docs/configure.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,21 @@ settings with pkg-config, or fail configuration if not possible.
756756

757757
Use `--with-systemdsystemunitdir=no` to disable this feature altogether.
758758

759+
--with-systemdsystempresetdir=PATH
760+
761+
Where to install Linux systemd unit presets (lists of services enabled
762+
or disabled by default). Useless and harmless on other OSes, including
763+
Linux distributions without systemd, just adding a little noise to the
764+
configure script output.
765+
766+
Use `--with-systemdsystempresetdir=auto` (default) to detect the settings
767+
using pkg-config if possible.
768+
769+
Use `--with-systemdsystempresetdir(=yes)` to require detection of these
770+
settings with pkg-config, or fail configuration if not possible.
771+
772+
Use `--with-systemdsystempresetdir=no` to disable this feature altogether.
773+
759774
--with-systemdshutdowndir=PATH
760775

761776
Where to install Linux systemd unit definitions for shutdown handling.

docs/man/upslog.txt

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ variables that interest you, format them, and write them to a file.
2222
The default format string includes variables that are supported by many
2323
common UPS models. See the description below to make your own.
2424

25+
NOTE: Historically this daemon supported logging of data for one UPS system
26+
(specified by the `-s` option) into one log file name or `stdout` (specified
27+
by the `-l` option). Later it allowed to log several devices (each into its
28+
destination) as specified by multiple `-m tuple` options. The two modes are
29+
effectively exclusive of each other (single-UPS options are ignored if tuples
30+
are also provided).
31+
2532
OPTIONS
2633
-------
2734

@@ -70,6 +77,8 @@ Store the results in this file.
7077
+
7178
You can use "-" for stdout, but upslog will remain in the foreground
7279
by default.
80+
+
81+
Ignored if you also provide `-m tuple` option(s).
7382

7483
*-F*::
7584
upslog will run in the foreground, regardless of logging target.
@@ -80,11 +89,25 @@ upslog will run in the background, regardless of logging target.
8089
*-s* 'ups'::
8190
Monitor this UPS. The format for this option is
8291
+upsname[@hostname[:port]]+. The default hostname is "localhost".
92+
+
93+
Ignored if you also provide `-m tuple` option(s).
8394

8495
*-m* 'tuple'::
85-
Monitor multiple UPSs. The format for this option is a tuple of
86-
ups and logfile separated by commas. An example would be:
87-
`upsname@hostname:9999,/var/log/nut/cps.log`
96+
Monitor multiple UPSs (provided several instances of such option).
97+
+
98+
Overrides the single-UPS settings passed by `-s` and `-l` options.
99+
+
100+
The format for this option is a tuple of UPS system and log file
101+
specification, separated by commas. An example would be:
102+
----
103+
upsname@hostname:9999,/var/log/nut/cps.log
104+
----
105+
+
106+
Tuples may specify `-` as the logfile, to emit messages on `stdout`
107+
(e.g. to be collected by the system journal for services).
108+
+
109+
Use of `stdout` via tuple-based logging specifications does not
110+
imply that upslog will remain in the foreground by default.
88111

89112
*-u* 'username'::
90113

docs/nut.dict

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
personal_ws-1.1 en 3274 utf-8
1+
personal_ws-1.1 en 3275 utf-8
22
AAC
33
AAS
44
ABI
@@ -2966,6 +2966,7 @@ syslogd
29662966
systemctl
29672967
systemd
29682968
systemdshutdowndir
2969+
systemdsystempresetdir
29692970
systemdsystemunitdir
29702971
systemdtmpfilesdir
29712972
systemtest

scripts/Solaris/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
/precheck.py
88
/preproto.pl
99
/svc-nut-server
10+
/svc-nut-logger
1011
/svc-nut-monitor
1112
/nut-driver.xml
1213
/nut-driver-enumerator.xml
14+
/nut-logger.xml
1315
/nut-monitor.xml
1416
/nut-server.xml
1517
/nut.xml

scripts/Solaris/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ PYTHON = @PYTHON@
88
SOLARIS_SMF_MANIFESTS = \
99
nut.xml \
1010
nut-server.xml \
11+
nut-logger.xml \
1112
nut-monitor.xml \
1213
nut-driver.xml \
1314
nut-driver-enumerator.xml
1415

1516
SOLARIS_SMF_METHODSCRIPTS = \
1617
svc-nut-server \
18+
svc-nut-logger \
1719
svc-nut-monitor
1820

1921
if WITH_SOLARIS_SMF

0 commit comments

Comments
 (0)