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 <redacted>
PKG_NAME:=nut
PKG_VERSION:=2.8.5
-PKG_RELEASE:=3
+PKG_RELEASE:=4
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=https://www.networkupstools.org/source/2.8/
# shellcheck disable=SC2016
echo '/cgi-bin/nut:root:$p$root' >>/etc/httpd.conf
if ! /etc/init.d/uhttpd restart; then
- logger -s -t nut-cgi "Failed to restart uhttpd after http.conf update"
+ logger -t nut-cgi "Failed to restart uhttpd after http.conf update"
exit 1
fi
}
# shellcheck source=net/nut/files/functions.sh.functions
. "${IPKG_INSTROOT}"/lib/functions.sh || {
# Before our sourcing error logging definitions are sourced
- logger -s -t nut-usb-hotplug "Unable to source 'functions.sh' in 'libhid-ups' hotplug. Bailing"
+ logger -t nut-usb-hotplug "Unable to source 'functions.sh' in 'libhid-ups' hotplug. Bailing"
exit 1
}
# shellcheck source=net/nut/files/nut-common.sh.functions
. "${IPKG_INSTROOT}"/lib/functions/nut/nut-common.sh || {
# Before our sourcing error logging definitions are sourced
- logger -s -t nut-usb-hotplug "Unable to source 'nut-common.sh' in 'libhid-ups' hotplug. Bailing"
+ logger -t nut-usb-hotplug "Unable to source 'nut-common.sh' in 'libhid-ups' hotplug. Bailing"
exit 1
}
# shellcheck source=net/nut/files/functions.sh.functions
. "${IPKG_INSTROOT}"/lib/functions.sh || {
# Before our sourcing error logging definitions are sourced
- logger -s -t nut-cgi "Unable to source 'functions.sh'"
+ logger -t nut-cgi "Unable to source 'functions.sh'"
exit 1
}
# shellcheck source=net/nut/files/nut-common.sh.functions
. "${IPKG_INSTROOT}"/lib/functions/nut/nut-common.sh || {
# Before our sourcing error logging definitions are sourced
- logger -s -t nut-cgi "Failed to load nut-common.sh"
+ logger -t nut-cgi "Failed to load nut-common.sh"
exit 1
}
local level="${4:-notice}"
local facility="${5:-daemon}"
- logger -s -t "$syslog_id" -p "${facility}.${level}" "'$reason' in '$current_script'" || {
+ logger -t "$syslog_id" -p "${facility}.${level}" "'$reason' in '$current_script'" || {
# We use 'tr' as changing case via variable parameter substitution is not available in ash on OpenWrt
# shellcheck disable=SC2018,SC2019
level="$(echo "$level" | tr 'a-z' 'A-Z')"
# shellcheck source=net/nut/files/functions.sh.functions
. "${IPKG_INSTROOT}"/lib/functions.sh || {
# Before our sourcing error logging definitions are sourced
- logger -s -t nut-monitor "Unable to source 'functions.sh' in 'nut-monitor'. Bailing"
+ logger -t nut-monitor "Unable to source 'functions.sh' in 'nut-monitor'. Bailing"
exit 1
}
# shellcheck source=net/nut/files/nut-common.sh.functions
. "${IPKG_INSTROOT}"/lib/functions/nut/nut-common.sh || {
# Before our sourcing error logging definitions are sourced
- logger -s -t nut-monitor "Unable to source 'nut-common.sh' in 'nut-monitor'. Bailing"
+ logger -t nut-monitor "Unable to source 'nut-common.sh' in 'nut-monitor'. Bailing"
exit 1
}
start_monitor_instance() {
procd_open_instance upsmon
procd_set_param respawn
- procd_set_param stderr 0 # stderr is just a dup of stdout + logger (with -s)
+ procd_set_param stderr 1
procd_set_param stdout 1
procd_set_param env NUT_QUIET_INIT_UPSNOTIFY=true
+ procd_set_param env NUT_DEBUG_SYSLOG="stderr"
procd_set_param reload_signal HUP
procd_set_param command /usr/sbin/upsmon
procd_append_param command -FF
# shellcheck source=net/nut/files/functions.sh.functions
. /lib/functions.sh || {
- logger -s -t nut-notify-exec "FATAL: Unable to source 'functions.sh'." || true
+ logger -t nut-notify-exec "FATAL: Unable to source 'functions.sh'." || true
exit 1
}
# Load and process nut_monitor (upsmon) configuration
config_load nut_monitor || {
- logger -s -t nut-notify-exec "FATAL: Loading 'nut_monitor' failed" || true
+ logger -t nut-notify-exec "FATAL: Loading 'nut_monitor' failed" || true
exit 1
}
# needed, doing nothing if a upsmon type section named 'upsmon' already
# exists).
uci set "nut_monitor.upsmon=upsmon" || {
- logger -s -t nut-notify-exec "Failed to ensure an upsmon section named upsmon exists" || true
+ logger -t nut-notify-exec "Failed to ensure an upsmon section named upsmon exists" || true
exit 1
}
fi
fi
uci set "nut_monitor.upsmon.defaultnotify"="$defaultnotify" || {
- logger -s -t nut-notify-exec "FATAL: Failed to set 'defaultnotify' for 'upsmon'" || true
+ 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 -s -t nut-notify-exec "ERROR: Failed to commit changes to nut_monitor" || true
+ logger -t nut-notify-exec "ERROR: Failed to commit changes to nut_monitor" || true
exit 1
}
# shellcheck source=net/nut/files/functions.sh.functions
. /lib/functions.sh || {
- logger -s -t nut-sched "FATAL: Unable to source 'functions.sh'" || true
+ logger -t nut-sched "FATAL: Unable to source 'functions.sh'" || true
exit 1
}
# Load and process nut_monitor (upsmon) configuration
config_load nut_monitor || {
- logger -s -t nut-sched "FATAL: loading 'nut_monitor' failed" || true
+ logger -t nut-sched "FATAL: loading 'nut_monitor' failed" || true
exit 1
}
if [ "${SKIP_ADD_NOTIFYCMD}" = "false" ]; then
# Ensure upsmon type section with the name upsmon exists
uci set "nut_monitor.upsmon=upsmon" || {
- logger -s -t nut-sched "Failed to ensure an upsmon section named upsmon exists" || true
+ logger -t nut-sched "Failed to ensure an upsmon section named upsmon exists" || true
exit 1
}
uci set "nut_monitor.upsmon.notifycmd=/usr/sbin/upssched" || {
- logger -s -t nut-sched "Failed to set notifycmd to upssched" || true
+ logger -t nut-sched "Failed to set notifycmd to upssched" || true
uci revert nut_monitor || true
exit 1
}
uci commit nut_monitor || {
- logger -s -t nut-sched "Failed to commit changes to nut_monitor" || true
+ logger -t nut-sched "Failed to commit changes to nut_monitor" || true
exit 1
}
fi
# shellcheck source=net/nut/files/functions.sh.functions
. "${IPKG_INSTROOT}"/lib/functions.sh || {
- logger -s -t nut-sendmail-notify "Unable to source 'functions.sh' in 'nut-sendmail-notify'. Bailing"
+ logger -t nut-sendmail-notify "Unable to source 'functions.sh' in 'nut-sendmail-notify'. Bailing"
exit 1
}
# shellcheck disable=SC1094
# shellcheck source=net/nut/files/nut-common.sh.functions
. "${IPKG_INSTROOT}"/lib/functions/nut/nut-common.sh || {
- logger -s -t nut-sendmail-notify "Unable to source 'nut-common.sh' in 'nut-sendmail-notify'. Bailing"
+ logger -t nut-sendmail-notify "Unable to source 'nut-common.sh' in 'nut-sendmail-notify'. Bailing"
exit 1
}
local reason="$1"
local syslog_id="nut-sendmail-notify"
local message_prefix="Message was not sent"
- logger -s -t "$syslog_id" "${message_prefix}: $reason" || {
+ logger -t "$syslog_id" "${message_prefix}: $reason" || {
printf "%s: %s: %s, and logging failed\n" "$syslog_id" "$message_prefix" "$reason" >&2
}
exit 1
# shellcheck source=net/nut/files/functions.sh.functions
. /lib/functions.sh || {
- logger -s -t nut-sendmail-notify "FATAL: Unable to source 'functions.sh'" || true
+ logger -t nut-sendmail-notify "FATAL: Unable to source 'functions.sh'" || true
exit 1
}
# Load and process nut_monitor (upsmon) configuration
config_load nut_monitor || {
- logger -s -t nut-sendmail-notify "FATAL: Loading 'nut_monitor' failed." || true
+ logger -t nut-sendmail-notify "FATAL: Loading 'nut_monitor' failed." || true
exit 1
}
if [ "${SKIP_ADD_NOTIFYCMD}" = "false" ]; then
# Ensure upsmon type section with the name upsmon exists
uci set "nut_monitor.upsmon=upsmon" || {
- logger -s -t nut-sendmail-notify "Failed to ensure an upsmon section named upsmon exists" || true
+ logger -t nut-sendmail-notify "Failed to ensure an upsmon section named upsmon exists" || true
exit 1
}
# never be reached. This is intentional. upssched takes precedence over
# nut-sendmail-notify, unless the user writes a script that supports both.
uci set "nut_monitor.upsmon.notifycmd=/usr/bin/nut-sendmail-notify" || {
- logger -s -t nut-sendmail-notify "Failed to set notifycmd to be nut-sendmail-notify" || true
+ logger -t nut-sendmail-notify "Failed to set notifycmd to be nut-sendmail-notify" || true
uci revert nut_monitor || true
exit 1
}
fi
uci commit nut_monitor || {
- logger -s -t nut-sendmail-notify "Failed to commit changes to nut_monitor" || true
+ logger -t nut-sendmail-notify "Failed to commit changes to nut_monitor" || true
exit 1
}
fi
# shellcheck source=net/nut/files/functions.sh.functions
. "${IPKG_INSTROOT}"/lib/functions.sh || {
# Before our sourcing error logging definitions are sourced
- logger -s -t nut-serial-hotplug "Unable to source 'functions.sh' in 'nut-serial' hotplug. Bailing"
+ logger -t nut-serial-hotplug "Unable to source 'functions.sh' in 'nut-serial' hotplug. Bailing"
exit 1
}
# shellcheck source=net/nut/files/nut-common.sh.functions
. "${IPKG_INSTROOT}"/lib/functions/nut/nut-common.sh || {
# Before our sourcing error logging definitions are sourced
- logger -s -t nut-serial-hotplug "Unable to source 'nut-common.sh' in 'nut-serial' hotplug. Bailing"
+ logger -t nut-serial-hotplug "Unable to source 'nut-common.sh' in 'nut-serial' hotplug. Bailing"
exit 1
}
# shellcheck source=net/nut/files/functions.sh.functions
. "${IPKG_INSTROOT}"/lib/functions.sh || {
# Before our sourcing error logging definitions are sourced
- logger -s -t "nut-server" "FATAL: Unable to source 'functions.sh' in 'nut-server'"
+ logger -t "nut-server" "FATAL: Unable to source 'functions.sh' in 'nut-server'"
exit 1
}
# shellcheck source=net/nut/files/nut-common.sh.functions
. "${IPKG_INSTROOT}"/lib/functions/nut/nut-common.sh || {
# Before our sourcing error logging definitions are sourced
- logger -s -t "nut-server" "FATAL: Unable to source 'nut-common.sh' in 'nut-server'"
+ logger -t "nut-server" "FATAL: Unable to source 'nut-common.sh' in 'nut-server'"
exit 1
}
procd_open_instance "$ups"
procd_set_param respawn
- procd_set_param stderr 0 # stderr is just a dup of stdout + logger (with -s)
+ procd_set_param stderr 1
procd_set_param stdout 1
+ procd_set_param env NUT_DEBUG_SYSLOG="stderr"
procd_set_param env NUT_QUIET_INIT_UPSNOTIFY=true
procd_set_param env NUT_STATEPATH="${STATEPATH}"
procd_set_param command "/usr/libexec/nut/${driver}"
config_get driver "$instance" driver
# Only stop not configured but running instances
if [ -z "$driver" ] && [ -n "$instance" ] && procd_running "nut-server" "$instance" >/dev/null 2>&1; then
- procd_kill "nut-server" "$instance" 2>&1 | logger -s -t nut-server
+ procd_kill "nut-server" "$instance" 2>&1 | logger -t nut-server
fi
done
set +f
procd_open_instance upsd
procd_set_param respawn
- procd_set_param stderr 0 # stderr is just a dup of stdout + logger (with -s)
+ procd_set_param stderr 1
procd_set_param stdout 1
+ procd_set_param env NUT_DEBUG_SYSLOG="stderr"
procd_set_param env NUT_QUIET_INIT_UPSNOTIFY=true
procd_set_param env NUT_STATEPATH="$STATEPATH"
procd_set_param command /usr/sbin/upsd
# If "nut-server" is active with no instances
# We don't care about the exit code of procd_kill, and logging its
# stderr can aid debugging.
- procd_kill "nut-server" 2>&1 | logger -s -t "nut-server"
+ procd_kill "nut-server" 2>&1 | logger -t "nut-server"
fi
}
# Informational log message, not error
logger -s -t "$service_name" "Performing '$secondary_command' $* for '$instance_name'"
set -f
- "$secondary_command" "$@" 2>&1 | logger -s -t "$service_name"
+ "$secondary_command" "$@" 2>&1 | logger -t "$service_name"
set +f
fi
# No signal sent is a valid possibility. Also, if sending a signal fails
# We're in an emergency shutdown; best effort shutdown and don't block
if [ -z "$1" ]; then
echo "$MISSING_UPS_INSTANCE_SKIP_MESSAGE" >&2
- logger -s -t nut-shutdown "$MISSING_UPS_INSTANCE_SKIP_MESSAGE" || true
+ logger -t nut-shutdown "$MISSING_UPS_INSTANCE_SKIP_MESSAGE" || true
return 1
fi
"$NUT_SERVER_INIT" stop "$1" || true
# with a proper UCI name (should never happen, hence skipping if it does)
if ! check_safe_name "$ups"; then
echo "$UNSAFE_UPS_INSTANCE_NAME_SKIP_MESSAGE" >&2
- logger -s -t nut-shutdown "$UNSAFE_UPS_INSTANCE_NAME_SKIP_MESSAGE" || true
+ logger -t nut-shutdown "$UNSAFE_UPS_INSTANCE_NAME_SKIP_MESSAGE" || true
return 1
fi
if [ -n "${IPKG_INSTROOT}" ]; then
echo "$NOT_A_LIVE_SYSTEM_BAIL_MESSAGE" >&2
# Improbable logging will work
- logger -s -t nut-shutdown "$NOT_A_LIVE_SYSTEM_BAIL_MESSAGE" || true
+ logger -t nut-shutdown "$NOT_A_LIVE_SYSTEM_BAIL_MESSAGE" || true
exit 1
fi
# live system) bail with an error.
# Logging probably won't work if /lib/functions.sh is not available but try
echo "$MISSING_LIB_FUNCTIONS_SH_BAIL_MESSAGE" >&2
- logger -s -t nut-shutdown "$MISSING_LIB_FUNCTIONS_SH_BAIL_MESSAGE" || true
+ logger -t nut-shutdown "$MISSING_LIB_FUNCTIONS_SH_BAIL_MESSAGE" || true
exit 1
}
DO_KILLPOWER="1"
disable_hotplug || true
echo "$MISSING_CONFIG_BAIL_MESSAGE" >&2 || true
- logger -s -t nut-shutdown "$MISSING_CONFIG_BAIL_MESSAGE" || true
+ logger -t nut-shutdown "$MISSING_CONFIG_BAIL_MESSAGE" || true
remount_filesystems_as_readonly || true
fi