]> git.99rst.org Git - openwrt-packages.git/commitdiff
nut: manage logging
authorDaniel F. Dickinson <redacted>
Sat, 18 Jul 2026 22:24:21 +0000 (18:24 -0400)
committerJosef Schlehofer <redacted>
Sun, 19 Jul 2026 09:23:51 +0000 (11:23 +0200)
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>
14 files changed:
net/nut/Makefile
net/nut/files/add_nut_httpd_conf.default
net/nut/files/libhid-ups.hotplug
net/nut/files/nut-cgi.init
net/nut/files/nut-common.sh.functions
net/nut/files/nut-monitor.init
net/nut/files/nut-notify-exec.default
net/nut/files/nut-sched.default
net/nut/files/nut-sendmail-notify
net/nut/files/nut-sendmail-notify.default
net/nut/files/nut-serial.hotplug
net/nut/files/nut-server.init
net/nut/files/nut-service.sh.functions
net/nut/files/nutshutdown

index e4010d837196ad3375167810616484d4e9009e1a..aeb758451b0ec290ae34749fe0e2240524cc356c 100644 (file)
@@ -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/
index 3937b3a84ba44d6546440d93f00e058bb2de036b..900ab0eba2a7a7458d4ca5ea4993c1add795b9cd 100644 (file)
@@ -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
 }
index aad52cf0bee7261e071c4c0608f1902d777177ab..93ec81ec02306ae2ca9eeb84b80591057dce5682 100644 (file)
@@ -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
 }
 
index c44c7773afe0b01cc87e5c507d6cf56ba3f3c434..f7e256a2f62d5b006b720401c57b213c3c227cca 100644 (file)
@@ -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
 }
 
index 368ef9b0aa7723bfa10f15a60308b8c42347d548..1b8a2a26fe09b28da21ccd3ae0ac99b565ebaa91 100644 (file)
@@ -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')"
index 82e63088d1c3007419b7d86434b3a2ba42b17eec..ae283033718a7ae2fc5eb82d0947611027181248 100644 (file)
@@ -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
index 242066b1cc82dae51313b0d1c264d5bba33cf0bb..61f5ec44ee70c126e75601067648f86571410f21 100644 (file)
@@ -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
 }
 
index e0636b4ee937f17075a5474050f6d9490fec5364..8840ad7284d2ab447b2c8acad1fe7fd2b5278788 100644 (file)
@@ -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
index 6cf9d2048b3ae6022a57a854e2a39a22a1ec24c8..b49de4bde3b49e0cef004c346f9448dfcdc21f26 100644 (file)
@@ -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
index 05c63f4e9ee9ce4f771771cc5e025f87f87cbae0..0001853514c728a56c7297ebed1caba603b757ab 100644 (file)
@@ -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
index d6ebd70d1bd2824204a3b8b4dd92d4684bc4e8cb..3669a0c5ca375019375c5e19bd1b628c3638096d 100644 (file)
@@ -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
 }
 
index 1467bd516e0be4604acc664f3a8832faa6b698db..5b6d35f7959f18ebe0a5780bc46649b7584d61b6 100644 (file)
@@ -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
 }
 
index 1e6ab927e02ef7fc5a9dd262a7bbc156e61ec33c..54e138cdc26260af700556d114814ad6876b7229 100644 (file)
@@ -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
index 586d173176afd65d52df6ee2ab0bec4394b7e776..5fc867c35561e61b9cee977a7c09eef59805a303 100644 (file)
@@ -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
git clone https://git.99rst.org/PROJECT