Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions NEWS.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,13 @@ as part of https://github.com/networkupstools/nut/issues/1410 solution.

- Extended Linux systemd support with optional notifications about daemon
state (READY, RELOADING, STOPPING) and watchdog keep-alive messages [#1590]
* Normally *inability* to send such notifications (e.g. lack of systemd
or similar framework on the particular platform) would be reported once
per daemon uptime on its console log, to help troubleshooting situations
where such lack of notifications can cause automated service restarts.
These messages can be hidden by setting `NUT_QUIET_INIT_UPSNOTIFY=true`
environment variable in init-scripts on platforms where such frameworks
are not expected. [#2136]

- Extended Linux systemd units with aliases named after the daemons:
`nut-server.service` as `upsd.service`, and `nut-monitor.service` as
Expand Down
53 changes: 46 additions & 7 deletions common/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ static int upsnotify_reported_disabled_systemd = 0;
#endif
/* Similarly for only reporting once if the notification subsystem is not built-in */
static int upsnotify_reported_disabled_notech = 0;
static int upsnotify_report_verbosity = -1;

/* the reason we define UPS_VERSION as a static string, rather than a
macro, is to make dependency tracking easier (only common.o depends
Expand Down Expand Up @@ -796,6 +797,34 @@ int upsnotify(upsnotify_state_t state, const char *fmt, ...)
# endif /* HAVE_SD_NOTIFY */
#endif /* WITH_LIBSYSTEMD */

/* Were we asked to be quiet on the console? */
if (upsnotify_report_verbosity < 0) {
char *quiet_init = getenv("NUT_QUIET_INIT_UPSNOTIFY");
if (quiet_init == NULL) {
/* No envvar, default is to inform once on the console */
upsnotify_report_verbosity = 0;
} else {
/* Envvar is set, does it tell us to be quiet?
* NOTE: Empty also means "yes" */
if (*quiet_init == '\0'
|| (strcasecmp(quiet_init, "true")
&& strcasecmp(quiet_init, "yes")
&& strcasecmp(quiet_init, "on")
&& strcasecmp(quiet_init, "1") )
) {
upsdebugx(1,
"NUT_QUIET_INIT_UPSNOTIFY='%s' value "
"was not recognized, ignored",
quiet_init);
upsnotify_report_verbosity = 0;
} else {
/* Avoid the verbose message below
* (only seen with non-zero debug) */
upsnotify_report_verbosity = 1;
}
}
}

/* Prepare the message (if any) as a string */
msgbuf[0] = '\0';
if (fmt) {
Expand Down Expand Up @@ -832,14 +861,16 @@ int upsnotify(upsnotify_state_t state, const char *fmt, ...)
NUT_UNUSED_VARIABLE(buf);
NUT_UNUSED_VARIABLE(msglen);
if (!upsnotify_reported_disabled_systemd)
upsdebugx(0, "%s: notify about state %i with libsystemd: "
"skipped for libcommonclient build, "
"will not spam more about it", __func__, state);
upsdebugx(upsnotify_report_verbosity,
"%s: notify about state %i with libsystemd: "
"skipped for libcommonclient build, "
"will not spam more about it", __func__, state);
upsnotify_reported_disabled_systemd = 1;
# else
if (!getenv("NOTIFY_SOCKET")) {
if (!upsnotify_reported_disabled_systemd)
upsdebugx(0, "%s: notify about state %i with libsystemd: "
upsdebugx(upsnotify_report_verbosity,
"%s: notify about state %i with libsystemd: "
"was requested, but not running as a service unit now, "
"will not spam more about it",
__func__, state);
Expand Down Expand Up @@ -1110,17 +1141,25 @@ int upsnotify(upsnotify_state_t state, const char *fmt, ...)
) {
if (ret == -127) {
if (!upsnotify_reported_disabled_notech)
upsdebugx(0, "%s: failed to notify about state %i: no notification tech defined, will not spam more about it", __func__, state);
upsdebugx(upsnotify_report_verbosity,
"%s: failed to notify about state %i: "
"no notification tech defined, "
"will not spam more about it",
__func__, state);
upsnotify_reported_disabled_notech = 1;
} else {
upsdebugx(6, "%s: failed to notify about state %i", __func__, state);
upsdebugx(6,
"%s: failed to notify about state %i",
__func__, state);
}
}

#if defined(WITH_LIBSYSTEMD) && (WITH_LIBSYSTEMD)
# if ! DEBUG_SYSTEMD_WATCHDOG
if (state == NOTIFY_STATE_WATCHDOG && !upsnotify_reported_watchdog_systemd) {
upsdebugx(0, "%s: logged the systemd watchdog situation once, will not spam more about it", __func__);
upsdebugx(upsnotify_report_verbosity,
"%s: logged the systemd watchdog situation once, "
"will not spam more about it", __func__);
upsnotify_reported_watchdog_systemd = 1;
}
# endif
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 3257 utf-8
personal_ws-1.1 en 3258 utf-8
AAC
AAS
ABI
Expand Down Expand Up @@ -1327,6 +1327,7 @@ UPSDESC
UPSHOST
UPSIMAGEPATH
UPSLC
UPSNOTIFY
UPSOutletSystemOutletDelayBeforeReboot
UPSOutletSystemOutletDelayBeforeShutdown
UPSOutletSystemOutletDelayBeforeStartup
Expand Down
3 changes: 3 additions & 0 deletions scripts/Aix/nut.init.in
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ NUTUSER="@RUN_AS_USER@"
NUTGROUP="@RUN_AS_GROUP@"
NUT_VAR_LOCK="/var/locks/ups"

NUT_QUIET_INIT_UPSNOTIFY=true
export NUT_QUIET_INIT_UPSNOTIFY

if [ -f "$CONFIG" ] ; then
. "$CONFIG"

Expand Down
3 changes: 3 additions & 0 deletions scripts/HP-UX/nut-drvctl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ umask 022
PATH=/usr/sbin:/usr/bin:/sbin
export PATH

NUT_QUIET_INIT_UPSNOTIFY=true
export NUT_QUIET_INIT_UPSNOTIFY

WHAT='NUT UPS driver (Network UPS Tools -- http://www.exploits.org/nut)'
WHAT_PATH=/opt/nut/bin/upsdrvctl
WHAT_CONFIG=/etc/rc.config.d/nut-drvctl
Expand Down
3 changes: 3 additions & 0 deletions scripts/HP-UX/nut-upsd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ umask 022
PATH=/usr/sbin:/usr/bin:/sbin
export PATH

NUT_QUIET_INIT_UPSNOTIFY=true
export NUT_QUIET_INIT_UPSNOTIFY

WHAT='NUT UPS daemon (Network UPS Tools -- http://www.exploits.org/nut)'
WHAT_PATH=/opt/nut/sbin/upsd
WHAT_CONFIG=/etc/rc.config.d/nut-upsd
Expand Down
3 changes: 3 additions & 0 deletions scripts/HP-UX/nut-upsmon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ umask 022
PATH=/usr/sbin:/usr/bin:/sbin
export PATH

NUT_QUIET_INIT_UPSNOTIFY=true
export NUT_QUIET_INIT_UPSNOTIFY

WHAT='NUT UPS monitor (Network UPS Tools -- http://www.exploits.org/nut)'
WHAT_PATH=/opt/nut/sbin/upsmon
WHAT_CONFIG=/etc/rc.config.d/nut-upsmon
Expand Down
3 changes: 3 additions & 0 deletions scripts/RedHat/upsd.in
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ fi
# if there are no config file, bail out
[ -f "$UPSDCONF" ] && [ -f "$UPSCONF" ] || exit 0

NUT_QUIET_INIT_UPSNOTIFY=true
export NUT_QUIET_INIT_UPSNOTIFY

runcmd() {
echo -n "$1 "
shift
Expand Down
3 changes: 3 additions & 0 deletions scripts/RedHat/upsmon.in
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ if [ -n "$NUT_SBINDIR" -a -d "$NUT_SBINDIR" ]; then
PATH="$NUT_SBINDIR:$PATH"
fi

NUT_QUIET_INIT_UPSNOTIFY=true
export NUT_QUIET_INIT_UPSNOTIFY

# See how we are called.
case "$1" in
start)
Expand Down
4 changes: 4 additions & 0 deletions scripts/Solaris/nut.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ NUT_SBIN_DIR="${NUT_DIR}/sbin"
NUT_LIB_DIR="${NUT_DIR}/lib"
CONFIG="@CONFPATH@/nut.conf"

# We anticipate some tighter integration with SMF later:
#NUT_QUIET_INIT_UPSNOTIFY=true
#export NUT_QUIET_INIT_UPSNOTIFY

if [ -f "$CONFIG" ] ; then
. "$CONFIG"
fi
Expand Down
4 changes: 4 additions & 0 deletions scripts/Solaris/svc-nut-monitor.in
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ CONFIG="@CONFPATH@/nut.conf"
NUTUSER="@RUN_AS_USER@"
NUTGROUP="@RUN_AS_GROUP@"

# We anticipate some tighter integration with SMF later:
#NUT_QUIET_INIT_UPSNOTIFY=true
#export NUT_QUIET_INIT_UPSNOTIFY

if [ -f "$CONFIG" ] ; then
. "$CONFIG"
fi
Expand Down
4 changes: 4 additions & 0 deletions scripts/Solaris/svc-nut-server.in
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ NUTGROUP="`svcprop -p nut/NUTGROUP $SMF_FMRI`" \
&& [ -n "$NUTGROUP" ] \
|| NUTGROUP="@RUN_AS_GROUP@"

# We anticipate some tighter integration with SMF later:
#NUT_QUIET_INIT_UPSNOTIFY=true
#export NUT_QUIET_INIT_UPSNOTIFY

if [ -f "$CONFIG" ] ; then
. "$CONFIG"
fi
Expand Down
5 changes: 4 additions & 1 deletion scripts/Solaris8/S99upsmon
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ export PATH

UPSDPATH=/usr/local/ups/sbin

NUT_QUIET_INIT_UPSNOTIFY=true
export NUT_QUIET_INIT_UPSNOTIFY

# See how we are called.
case "$1" in
'start')
Expand All @@ -19,7 +22,7 @@ case "$1" in
$UPSDPATH/upsmon >/dev/console 2>&1
touch /var/lock/subsys/upsmon
fi
;;
;;
'stop')
echo "NUT Stopping UPS monitor "
/usr/bin/pkill -x upsmon
Expand Down