Skip to content

Commit

Permalink
Merge pull request networkupstools#2746 from jimklimov/issue-1803
Browse files Browse the repository at this point in the history
Introduce service wrapping for `upslog` client daemon, and `nut-systemd.preset` file

Signed-off-by: Gong Zhile <[email protected]>
  • Loading branch information
jimklimov authored and goodspeed34 committed Jan 4, 2025
2 parents 5d832b9 + ea480a5 commit a4fdbf8
Show file tree
Hide file tree
Showing 28 changed files with 506 additions and 34 deletions.
1 change: 1 addition & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ DISTCHECK_VALGRIND_FLAGS = --with-all=auto --with-ssl=auto --with-doc=skip --wit
# Note: this rule uses envvar DISTCHECK_FLAGS expanded at run-time
DISTCHECK_CONFIGURE_FLAGS = ${DISTCHECK_FLAGS} \
--with-systemdsystemunitdir='$${prefix}/lib/systemd/system' \
--with-systemdsystempresetdir='$${prefix}/usr/lib/systemd/system-preset' \
--with-systemdshutdowndir='$${prefix}/lib/systemd/system-shutdown' \
--with-systemdtmpfilesdir='$${prefix}/usr/lib/tmpfiles.d' \
--with-augeas-lenses-dir='$${prefix}/usr/share/augeas/lenses' \
Expand Down
2 changes: 2 additions & 0 deletions NEWS.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,8 @@ https://github.com/networkupstools/nut/milestone/11
should be handled similar (avoid stale UPS data and rash decisions)
for summer/winter time change on non-UTC deployments, a debugger
suspending the `upsmon` process, etc. [#2597]
* Introduced delivery of default systemd presets (lists of enabled/disabled
units). [#2721]
- gamatronic driver revised for safer memory operations; this was reported
to have fixed a Segmentation Fault seen in earlier NUT releases with
Expand Down
5 changes: 5 additions & 0 deletions UPGRADING.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ Changes from 2.8.2 to 2.8.3
Please use it, it immensely helps with community troubleshooting!
[issue #1949]
- When packaging or custom-building for (Linux) distributions with systemd,
you can now take advantage of `nut-systemd.preset` file to enable or
disable certain NUT units by default; its comments document each choice.
[issue #2721]
- Reference packages prepared by `make package` should now separate the
`PACKAGE_VERSION` from the platform-dependent prefix by a dash character
in the ultimate package file name. Previously they were glued together
Expand Down
5 changes: 5 additions & 0 deletions clients/upslog.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,15 @@ static void help(const char *prog)
printf(" -F - stay foregrounded even if logging into a file\n");
printf(" -B - stay backgrounded even if logging to stdout\n");
printf(" -p <pidbase> - Base name for PID file (defaults to \"%s\")\n", prog);
printf(" - NOTE: PID file is written regardless of fore/back-grounding\n");
printf(" -s <ups> - Monitor UPS <ups> - <upsname>@<host>[:<port>]\n");
printf(" - Example: -s myups@server\n");
printf(" -m <tuple> - Monitor UPS <ups,logfile>\n");
printf(" - Example: -m myups@server,/var/log/myups.log\n");
printf(" - NOTE: You can use '-' as logfile for stdout\n");
printf(" and it would not imply foregrounding\n");
printf(" - NOTE: '-s ups' and/or '-l file' options are ignored\n");
printf(" if tuples are used, but you can specify many tuples\n");
printf(" -u <user> - Switch to <user> if started as root\n");
printf(" -V - Display the version of this software\n");
printf(" -h - Display this help text\n");
Expand Down
104 changes: 91 additions & 13 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -3997,11 +3997,17 @@ AC_ARG_WITH([systemdsystemunitdir],
case "${systemdsystemunitdir}" in
yes|auto|"")
AS_IF([test x"$have_PKG_CONFIG" = xyes],
[systemdsystemunitdir="`$PKG_CONFIG --variable=systemdsystemunitdir systemd 2>/dev/null`" && test -n "$systemdsystemunitdir" || systemdsystemunitdir="`$PKG_CONFIG --variable=systemdsystemunitdir libsystemd 2>/dev/null`"],
[AS_IF([test "${systemdsystemunitdir}" = yes],
[def_systemdsystemunitdir="`$PKG_CONFIG --variable=systemdsystemunitdir systemd 2>/dev/null`" && test -n "$def_systemdsystemunitdir" || \
def_systemdsystemunitdir="`$PKG_CONFIG --variable=systemdsystemunitdir libsystemd 2>/dev/null`" || def_systemdsystemunitdir=""],
[def_systemdsystemunitdir=""])

AS_IF([test x"${def_systemdsystemunitdir}" = x], [
AS_IF([test "${systemdsystemunitdir}" = yes],
[AC_MSG_ERROR([--with-systemdsystemunitdir=${systemdsystemunitdir} was requested, but PKG_CONFIG could not be queried for the system settings])])
systemdsystemunitdir=""
])
systemdsystemunitdir=""
], [systemdsystemunitdir="${def_systemdsystemunitdir}"])

unset def_systemdsystemunitdir
;;
no)
systemdsystemunitdir=""
Expand Down Expand Up @@ -4029,6 +4035,48 @@ dnl This option is only provided so that make distcheck can override it,
dnl otherwise we ask pkg-config whenever --with-systemdsystemunitdir is
dnl given

dnl Similarly for presets (list of svcs enabled/disabled by default)
AC_MSG_CHECKING(whether to install systemd preset files)
AC_ARG_WITH([systemdsystempresetdir],
[AS_HELP_STRING([--with-systemdsystempresetdir=DIR], [Directory for systemd preset files (auto)])],
[systemdsystempresetdir="${withval}"],
[systemdsystempresetdir="auto"])

dnl Note: this option is enabled only if systemdsystemunitdir is not trivial
if test -n "${systemdsystemunitdir}"; then
case "${systemdsystempresetdir}" in
yes|auto|"")
AS_IF([test x"$have_PKG_CONFIG" = xyes],
[def_systemdsystempresetdir="`$PKG_CONFIG --variable=systemdsystempresetdir systemd 2>/dev/null`" && test -n "$def_systemdsystempresetdir" || \
def_systemdsystempresetdir="`$PKG_CONFIG --variable=systemdsystempresetdir libsystemd 2>/dev/null`" || def_systemdsystempresetdir=""],
[def_systemdsystempresetdir=""])

AS_IF([test x"${def_systemdsystempresetdir}" = x], [
AS_IF([test "${systemdsystempresetdir}" = yes],
[AC_MSG_ERROR([--with-systemdsystempresetdir=${systemdsystempresetdir} was requested, but PKG_CONFIG could not be queried for the system settings])])
systemdsystempresetdir=""
], [systemdsystempresetdir="${def_systemdsystempresetdir}"])

unset def_systemdsystempresetdir
;;
no)
systemdsystempresetdir=""
;;
*)
AS_IF([test -d "${systemdsystempresetdir}"], [],
[AC_MSG_WARN([--with-systemdsystempresetdir='${systemdsystempresetdir}' was requested, but that location does not currently exist in build environment - just so you know...])])
;;
esac
fi
if test "${systemdsystempresetdir}" = "auto" ; then systemdsystempresetdir=""; fi
if test -n "${systemdsystempresetdir}"; then
AC_MSG_RESULT(using ${systemdsystempresetdir})
NUT_REPORT_PATH_INTEGRATIONS([Service unit presets for systemd], [${systemdsystempresetdir}])
else
AC_MSG_RESULT(no)
fi

dnl Similarly for shutdown integration hooks
AC_MSG_CHECKING(whether to install systemd shutdown files)
AC_ARG_WITH([systemdshutdowndir],
AS_HELP_STRING([--with-systemdshutdowndir=DIR], [Directory for systemd shutdown scripts (auto)]),
Expand All @@ -4039,11 +4087,17 @@ if test -n "${systemdsystemunitdir}"; then
case "${systemdshutdowndir}" in
yes|auto|"")
AS_IF([test x"$have_PKG_CONFIG" = xyes],
[systemdshutdowndir="`$PKG_CONFIG --variable=systemdshutdowndir systemd 2>/dev/null`" && test -n "$systemdshutdowndir" || systemdshutdowndir="`$PKG_CONFIG --variable=systemdshutdowndir libsystemd 2>/dev/null`"],
[AS_IF([test "${systemdshutdowndir}" = yes],
[def_systemdshutdowndir="`$PKG_CONFIG --variable=systemdshutdowndir systemd 2>/dev/null`" && test -n "$def_systemdshutdowndir" || \
def_systemdshutdowndir="`$PKG_CONFIG --variable=systemdshutdowndir libsystemd 2>/dev/null`" || def_systemdshutdowndir=""],
[def_systemdshutdowndir=""])

AS_IF([test x"${def_systemdshutdowndir}" = x], [
AS_IF([test "${systemdshutdowndir}" = yes],
[AC_MSG_ERROR([--with-systemdshutdowndir=${systemdshutdowndir} was requested, but PKG_CONFIG could not be queried for the system settings])])
systemdshutdowndir=""
])
systemdshutdowndir=""
], [systemdshutdowndir="${def_systemdshutdowndir}"])

unset def_systemdshutdowndir
;;
no)
systemdshutdowndir=""
Expand Down Expand Up @@ -4072,11 +4126,17 @@ AC_ARG_WITH([systemdtmpfilesdir],
case "${systemdtmpfilesdir}" in
yes|auto|"")
AS_IF([test x"$have_PKG_CONFIG" = xyes],
[systemdtmpfilesdir="`$PKG_CONFIG --variable=tmpfilesdir systemd 2>/dev/null`" && test -n "$systemdtmpfilesdir" || systemdtmpfilesdir="`$PKG_CONFIG --variable=tmpfilesdir libsystemd 2>/dev/null`"],
[AS_IF([test "${systemdtmpfilesdir}" = yes],
[def_systemdtmpfilesdir="`$PKG_CONFIG --variable=tmpfilesdir systemd 2>/dev/null`" && test -n "$def_systemdtmpfilesdir" || \
def_systemdtmpfilesdir="`$PKG_CONFIG --variable=tmpfilesdir libsystemd 2>/dev/null`" || def_systemdtmpfilesdir=""],
[def_systemdtmpfilesdir=""])

AS_IF([test x"${def_systemdtmpfilesdir}" = x], [
AS_IF([test "${systemdtmpfilesdir}" = yes],
[AC_MSG_ERROR([--with-systemdtmpfilesdir=${systemdtmpfilesdir} was requested, but PKG_CONFIG could not be queried for the system settings])])
systemdtmpfilesdir=""
])
systemdtmpfilesdir=""
], [systemdtmpfilesdir="${def_systemdtmpfilesdir}"])

unset def_systemdtmpfilesdir
;;
no)
systemdtmpfilesdir=""
Expand Down Expand Up @@ -4167,6 +4227,8 @@ AS_IF([test x"${with_libsystemd}" = xyes && test x"${SYSTEMD_SUPPORTS_DAEMON_TYP
dnl needed for `upsd -c reload` in legacy scripts and old habits to work:
SYSTEMD_DAEMON_ARGS_UPSD="-FF"
SYSTEMD_DAEMON_TYPE_UPSD="notify"
SYSTEMD_DAEMON_ARGS_UPSLOG="-F"
SYSTEMD_DAEMON_TYPE_UPSLOG="notify"
SYSTEMD_DAEMON_ARGS_UPSMON="-F"
SYSTEMD_DAEMON_TYPE_UPSMON="notify"
SYSTEMD_DAEMON_ARGS_DRIVER="-FF"
Expand All @@ -4183,29 +4245,36 @@ AS_IF([test x"${with_libsystemd}" = xyes && test x"${SYSTEMD_SUPPORTS_DAEMON_TYP
SYSTEMD_DAEMON_NOTIFYACCESS_DRIVER="NotifyAccess=all"
dnl Similar for UPSMON with its two processes:
SYSTEMD_DAEMON_NOTIFYACCESS_UPSMON="NotifyAccess=all"
dnl UPSD is started directly by systemd and do not fork:
dnl UPSD is started directly by systemd and does not fork:
SYSTEMD_DAEMON_NOTIFYACCESS_UPSD="NotifyAccess=main"
dnl Similarly for upslog (per settings above):
SYSTEMD_DAEMON_NOTIFYACCESS_UPSLOG="NotifyAccess=main"
dnl Note: at this time we do not pre-define watchdog settings,
dnl to avoid breaking something by a poorly hardcoded guess.
dnl This is something end-users should do for their deployment,
dnl especially for drivers
SYSTEMD_DAEMON_WATCHDOG_DRIVER="#WatchdogSec=240s"
SYSTEMD_DAEMON_WATCHDOG_UPSD="#WatchdogSec=240s"
SYSTEMD_DAEMON_WATCHDOG_UPSLOG="#WatchdogSec=240s"
SYSTEMD_DAEMON_WATCHDOG_UPSMON="#WatchdogSec=240s"
], [
dnl "Usual" daemons that happen to be spawned by systemd
SYSTEMD_DAEMON_ARGS_UPSD="-F"
SYSTEMD_DAEMON_TYPE_UPSD="simple"
SYSTEMD_DAEMON_ARGS_UPSLOG="-F"
SYSTEMD_DAEMON_TYPE_UPSLOG="simple"
SYSTEMD_DAEMON_ARGS_UPSMON="-F"
SYSTEMD_DAEMON_TYPE_UPSMON="simple"
SYSTEMD_DAEMON_ARGS_DRIVER=""
SYSTEMD_DAEMON_TYPE_DRIVER="forking"
SYSTEMD_DAEMON_NOTIFYACCESS_DRIVER=""
SYSTEMD_DAEMON_NOTIFYACCESS_UPSD=""
SYSTEMD_DAEMON_NOTIFYACCESS_UPSLOG=""
SYSTEMD_DAEMON_NOTIFYACCESS_UPSMON=""
dnl Watchdog should not be configured for not-notifying units, right?
SYSTEMD_DAEMON_WATCHDOG_DRIVER="#WatchdogSec=240s"
SYSTEMD_DAEMON_WATCHDOG_UPSD="#WatchdogSec=240s"
SYSTEMD_DAEMON_WATCHDOG_UPSLOG="#WatchdogSec=240s"
SYSTEMD_DAEMON_WATCHDOG_UPSMON="#WatchdogSec=240s"
])

Expand Down Expand Up @@ -4924,14 +4993,18 @@ AC_SUBST(LIBSYSTEMD_CFLAGS)
AC_SUBST(LIBSYSTEMD_LIBS)
AC_SUBST(SYSTEMD_DAEMON_ARGS_UPSD)
AC_SUBST(SYSTEMD_DAEMON_TYPE_UPSD)
AC_SUBST(SYSTEMD_DAEMON_ARGS_UPSLOG)
AC_SUBST(SYSTEMD_DAEMON_TYPE_UPSLOG)
AC_SUBST(SYSTEMD_DAEMON_ARGS_UPSMON)
AC_SUBST(SYSTEMD_DAEMON_TYPE_UPSMON)
AC_SUBST(SYSTEMD_DAEMON_ARGS_DRIVER)
AC_SUBST(SYSTEMD_DAEMON_TYPE_DRIVER)
AC_SUBST(SYSTEMD_DAEMON_NOTIFYACCESS_DRIVER)
AC_SUBST(SYSTEMD_DAEMON_NOTIFYACCESS_UPSD)
AC_SUBST(SYSTEMD_DAEMON_NOTIFYACCESS_UPSLOG)
AC_SUBST(SYSTEMD_DAEMON_NOTIFYACCESS_UPSMON)
AC_SUBST(SYSTEMD_DAEMON_WATCHDOG_UPSD)
AC_SUBST(SYSTEMD_DAEMON_WATCHDOG_UPSLOG)
AC_SUBST(SYSTEMD_DAEMON_WATCHDOG_UPSMON)
AC_SUBST(SYSTEMD_DAEMON_WATCHDOG_DRIVER)
AC_SUBST(SYSTEMD_TMPFILES_PROGRAM)
Expand Down Expand Up @@ -4972,6 +5045,7 @@ AC_SUBST(htmldocdir)
AC_SUBST(htmlmandir)
AC_SUBST(pkgconfigdir)
AC_SUBST(systemdsystemunitdir)
AC_SUBST(systemdsystempresetdir)
AC_SUBST(systemdshutdowndir)
AC_SUBST(systemdtmpfilesdir)
AC_SUBST(auglensdir)
Expand Down Expand Up @@ -5592,7 +5666,9 @@ AC_CONFIG_FILES([
scripts/systemd/Makefile
scripts/systemd/nut.target
scripts/systemd/nut-common-tmpfiles.conf
scripts/systemd/nut-driver.target
scripts/systemd/[email protected]
scripts/systemd/nut-logger.service
scripts/systemd/nut-monitor.service
scripts/systemd/nut-server.service
scripts/systemd/nut-driver-enumerator.service
Expand All @@ -5602,6 +5678,7 @@ AC_CONFIG_FILES([
scripts/systemd/nut-driver-enumerator-daemon-activator.path
scripts/Solaris/nut-driver-enumerator.xml
scripts/Solaris/nut-driver.xml
scripts/Solaris/nut-logger.xml
scripts/Solaris/nut-monitor.xml
scripts/Solaris/nut-server.xml
scripts/Solaris/nut.xml
Expand Down Expand Up @@ -5638,6 +5715,7 @@ m4_foreach_w([SCRIPTFILE], [
scripts/upsdrvsvcctl/upsdrvsvcctl
scripts/systemd/nutshutdown
scripts/Solaris/svc-nut-server
scripts/Solaris/svc-nut-logger
scripts/Solaris/svc-nut-monitor
scripts/Solaris/precheck.py
scripts/Solaris/preinstall
Expand Down
15 changes: 15 additions & 0 deletions docs/configure.txt
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,21 @@ settings with pkg-config, or fail configuration if not possible.

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

--with-systemdsystempresetdir=PATH

Where to install Linux systemd unit presets (lists of services enabled
or disabled by default). Useless and harmless on other OSes, including
Linux distributions without systemd, just adding a little noise to the
configure script output.

Use `--with-systemdsystempresetdir=auto` (default) to detect the settings
using pkg-config if possible.

Use `--with-systemdsystempresetdir(=yes)` to require detection of these
settings with pkg-config, or fail configuration if not possible.

Use `--with-systemdsystempresetdir=no` to disable this feature altogether.

--with-systemdshutdowndir=PATH

Where to install Linux systemd unit definitions for shutdown handling.
Expand Down
29 changes: 26 additions & 3 deletions docs/man/upslog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ variables that interest you, format them, and write them to a file.
The default format string includes variables that are supported by many
common UPS models. See the description below to make your own.

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

OPTIONS
-------

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

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

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

*-u* 'username'::

Expand Down
3 changes: 2 additions & 1 deletion docs/nut.dict
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
personal_ws-1.1 en 3274 utf-8
personal_ws-1.1 en 3275 utf-8
AAC
AAS
ABI
Expand Down Expand Up @@ -2966,6 +2966,7 @@ syslogd
systemctl
systemd
systemdshutdowndir
systemdsystempresetdir
systemdsystemunitdir
systemdtmpfilesdir
systemtest
Expand Down
2 changes: 2 additions & 0 deletions scripts/Solaris/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
/precheck.py
/preproto.pl
/svc-nut-server
/svc-nut-logger
/svc-nut-monitor
/nut-driver.xml
/nut-driver-enumerator.xml
/nut-logger.xml
/nut-monitor.xml
/nut-server.xml
/nut.xml
Expand Down
2 changes: 2 additions & 0 deletions scripts/Solaris/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ PYTHON = @PYTHON@
SOLARIS_SMF_MANIFESTS = \
nut.xml \
nut-server.xml \
nut-logger.xml \
nut-monitor.xml \
nut-driver.xml \
nut-driver-enumerator.xml

SOLARIS_SMF_METHODSCRIPTS = \
svc-nut-server \
svc-nut-logger \
svc-nut-monitor

if WITH_SOLARIS_SMF
Expand Down
Loading

0 comments on commit a4fdbf8

Please sign in to comment.