From: Daniel F. Dickinson Date: Sat, 18 Jul 2026 22:24:21 +0000 (-0400) Subject: nut: manage logging X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=95e3d348f8dac1fff73f1e506b0c46ca17adafa4;p=openwrt-packages.git 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 --- diff --git a/net/nut/Makefile b/net/nut/Makefile index e4010d837..aeb758451 100644 --- a/net/nut/Makefile +++ b/net/nut/Makefile @@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk 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/ diff --git a/net/nut/files/add_nut_httpd_conf.default b/net/nut/files/add_nut_httpd_conf.default index 3937b3a84..900ab0eba 100644 --- a/net/nut/files/add_nut_httpd_conf.default +++ b/net/nut/files/add_nut_httpd_conf.default @@ -22,7 +22,7 @@ grep -q '^/cgi-bin/nut' /etc/httpd.conf 2>/dev/null || { # 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 } diff --git a/net/nut/files/libhid-ups.hotplug b/net/nut/files/libhid-ups.hotplug index aad52cf0b..93ec81ec0 100644 --- a/net/nut/files/libhid-ups.hotplug +++ b/net/nut/files/libhid-ups.hotplug @@ -16,7 +16,7 @@ # 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 } @@ -26,7 +26,7 @@ # 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 } diff --git a/net/nut/files/nut-cgi.init b/net/nut/files/nut-cgi.init index c44c7773a..f7e256a2f 100644 --- a/net/nut/files/nut-cgi.init +++ b/net/nut/files/nut-cgi.init @@ -35,7 +35,7 @@ UPSCGI_HOSTS_CONF="${UPSCGI_CONF_DIR}/hosts.conf" # 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 } @@ -45,7 +45,7 @@ UPSCGI_HOSTS_CONF="${UPSCGI_CONF_DIR}/hosts.conf" # 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 } diff --git a/net/nut/files/nut-common.sh.functions b/net/nut/files/nut-common.sh.functions index 368ef9b0a..1b8a2a26f 100644 --- a/net/nut/files/nut-common.sh.functions +++ b/net/nut/files/nut-common.sh.functions @@ -185,7 +185,7 @@ log_msg() { 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')" diff --git a/net/nut/files/nut-monitor.init b/net/nut/files/nut-monitor.init index 82e63088d..ae2830337 100644 --- a/net/nut/files/nut-monitor.init +++ b/net/nut/files/nut-monitor.init @@ -18,7 +18,7 @@ USE_PROCD=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-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 } @@ -28,7 +28,7 @@ USE_PROCD=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 } @@ -104,9 +104,10 @@ service_preconditions() { 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 diff --git a/net/nut/files/nut-notify-exec.default b/net/nut/files/nut-notify-exec.default index 242066b1c..61f5ec44e 100644 --- a/net/nut/files/nut-notify-exec.default +++ b/net/nut/files/nut-notify-exec.default @@ -26,7 +26,7 @@ # 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 } @@ -35,7 +35,7 @@ DEFAULTNOTIFY_IS_IGNORE="false" # 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 } @@ -48,7 +48,7 @@ else # 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 @@ -65,13 +65,13 @@ else 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 } diff --git a/net/nut/files/nut-sched.default b/net/nut/files/nut-sched.default index e0636b4ee..8840ad728 100644 --- a/net/nut/files/nut-sched.default +++ b/net/nut/files/nut-sched.default @@ -27,7 +27,7 @@ # 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 } @@ -36,7 +36,7 @@ SKIP_ADD_NOTIFYCMD="false" # 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 } @@ -50,18 +50,18 @@ fi 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 diff --git a/net/nut/files/nut-sendmail-notify b/net/nut/files/nut-sendmail-notify index 6cf9d2048..b49de4bde 100644 --- a/net/nut/files/nut-sendmail-notify +++ b/net/nut/files/nut-sendmail-notify @@ -15,7 +15,7 @@ # 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 } @@ -24,7 +24,7 @@ # 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 } @@ -33,7 +33,7 @@ log_send_failure_and_exit() { 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 diff --git a/net/nut/files/nut-sendmail-notify.default b/net/nut/files/nut-sendmail-notify.default index 05c63f4e9..000185351 100644 --- a/net/nut/files/nut-sendmail-notify.default +++ b/net/nut/files/nut-sendmail-notify.default @@ -27,7 +27,7 @@ # 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 } @@ -36,7 +36,7 @@ SKIP_ADD_NOTIFYCMD="false" # 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 } @@ -50,7 +50,7 @@ fi 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 } @@ -61,14 +61,14 @@ if [ "${SKIP_ADD_NOTIFYCMD}" = "false" ]; then # 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 diff --git a/net/nut/files/nut-serial.hotplug b/net/nut/files/nut-serial.hotplug index d6ebd70d1..3669a0c5c 100644 --- a/net/nut/files/nut-serial.hotplug +++ b/net/nut/files/nut-serial.hotplug @@ -16,7 +16,7 @@ # 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 } @@ -26,7 +26,7 @@ # 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 } diff --git a/net/nut/files/nut-server.init b/net/nut/files/nut-server.init index 1467bd516..5b6d35f79 100644 --- a/net/nut/files/nut-server.init +++ b/net/nut/files/nut-server.init @@ -29,7 +29,7 @@ USE_PROCD=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 } @@ -39,7 +39,7 @@ USE_PROCD=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 } @@ -101,8 +101,9 @@ start_ups_driver() { 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}" @@ -183,7 +184,7 @@ stop_no_longer_configured_instances() { 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 @@ -312,8 +313,9 @@ start_server_instance() { 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 @@ -399,7 +401,7 @@ stop_service_if_no_instances() { # 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 } diff --git a/net/nut/files/nut-service.sh.functions b/net/nut/files/nut-service.sh.functions index 1e6ab927e..54e138cdc 100644 --- a/net/nut/files/nut-service.sh.functions +++ b/net/nut/files/nut-service.sh.functions @@ -141,7 +141,7 @@ signal_instance() { # 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 diff --git a/net/nut/files/nutshutdown b/net/nut/files/nutshutdown index 586d17317..5fc867c35 100644 --- a/net/nut/files/nutshutdown +++ b/net/nut/files/nutshutdown @@ -53,7 +53,7 @@ stop_nut_server_instance() { # 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 @@ -76,7 +76,7 @@ shutdown_actual_ups() { # 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 @@ -138,7 +138,7 @@ do_forced_shutdown() { 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 @@ -148,7 +148,7 @@ 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 } @@ -184,7 +184,7 @@ elif [ -f "$NUT_KILLPOWER" ]; then 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