Files
packages/net/nut/files/nut-notify-exec.default
Daniel F. Dickinson 95e3d348f8 nut: manage logging
NUT (upstream) logging has changed. With the introduction of
NUT_DEBUG_SYSLOG we can set it to "stderr" and have NUT's messages
go to stderr only.

This avoid most duplicate messages when procd sends stderr to syslog.

The reverse (syslog only from NUT) is not a current configuration
option. See the section for NUT_DEBUG_SYSLOG at
https://networkupstools.org/docs/man/nut.conf.html#_directives

This is needed because we use '-FF' so that the daemons remain in the
foreground, which is required for procd to manage them. When using
'-FF' logging behaves differently in NUT than when backgrounded.

Unfortunately, there is still some work to be done upstream to
completely eliminate duplicate messages, so some message continue to
appear twice, though not neccessarily with the same facility.priority.

See also
https://github.com/jimklimov/nut/blob/0c3eed09b89cce1e5c0c65ca03d05b4612371cb8/UPGRADING.adoc#changes-from-282-to-283
and
https://github.com/openwrt/packages/pull/29896#issuecomment-5012737643

Conversely, the log messages the initscripts emit are now configured to
emit only to syslog and not to stderr. This avoids duplicates messages
caused by procd's automatic (not configurable) behaviour of sending
the initscript's stderr to syslog, while preserving the syslogid,
facility and priority we want.

Signed-off-by: Daniel F. Dickinson <dfdpublic@wildtechgarden.ca>
2026-07-19 11:23:51 +02:00

79 lines
2.6 KiB
Bash

#!/bin/sh
# In recent (relevant) versions of shellcheck busybox is a valid shell type
# shellcheck shell=busybox
# uci-defaults script to set notify flags to enable execution of notifycmd
# (set separate scripts) unless the user has configured that notifications
# should be ignored.
# IPKG_INSTROOT is intentionally only set when building an image and
# is intentionally empty on a live OpenWrt device
# Shellcheck source paths intentionally point to the location of files of
# the scripts in the development environment (where shellcheck is used), not
# on the live OpenWrt device
# In the nut-upssched package, this script lives in
# /etc/uci-defaults/70-notify-exec
# In the nut-sendmail-notify package, this script lives in
# /etc/uci-defaults/71-notify-exec
# The difference in names is required to avoid conflicting files should both
# packages be installed on the same device.
# Only run this uci-defaults script on a live OpenWrt device
[ -z "${IPKG_INSTROOT}" ] || exit 0
# shellcheck source=net/nut/files/functions.sh.functions
. /lib/functions.sh || {
logger -t nut-notify-exec "FATAL: Unable to source 'functions.sh'." || true
exit 1
}
# Flags for whether defaultnotify option is set to IGNORE
DEFAULTNOTIFY_IS_IGNORE="false"
# Load and process nut_monitor (upsmon) configuration
config_load nut_monitor || {
logger -t nut-notify-exec "FATAL: Loading 'nut_monitor' failed" || true
exit 1
}
config_get val "upsmon" defaultnotify
# shellcheck disable=SC2154
if [ "${val}" = "IGNORE" ]; then
DEFAULTNOTIFY_IS_IGNORE="true"
else
# Ensure upsmon type section with the name upsmon exists (creating if
# needed, doing nothing if a upsmon type section named 'upsmon' already
# exists).
uci set "nut_monitor.upsmon=upsmon" || {
logger -t nut-notify-exec "Failed to ensure an upsmon section named upsmon exists" || true
exit 1
}
fi
# Set default notifications to enable notifycmd unless set to ignore
if [ "${DEFAULTNOTIFY_IS_IGNORE}" = "true" ]; then
defaultnotify="IGNORE"
# We only support IGNORE, SYSLOG, and EXEC options to defaultnotify
# Since we want logging (SYSLOG) and require EXEC so that /usr/sbin/upssched
# gets called by NUT, we enforce EXEC as well, producing SYSLOG+EXEC, unless
# the user is ignoring all notifications.
else
defaultnotify="SYSLOG+EXEC"
fi
uci set "nut_monitor.upsmon.defaultnotify"="$defaultnotify" || {
logger -t nut-notify-exec "FATAL: Failed to set 'defaultnotify' for 'upsmon'" || true
uci revert nut_monitor || true
exit 1
}
uci commit nut_monitor || {
logger -t nut-notify-exec "ERROR: Failed to commit changes to nut_monitor" || true
exit 1
}
exit 0