]> git.99rst.org Git - openwrt-packages.git/commitdiff
nut: do not trigger on interface activity by default
authorDaniel F. Dickinson <redacted>
Thu, 2 Jul 2026 22:50:40 +0000 (18:50 -0400)
committerJosef Schlehofer <redacted>
Wed, 15 Jul 2026 07:34:39 +0000 (09:34 +0200)
The defaults were triggiering on any activity on the network, which
caused excessive restarts. So default to no interface trigger, with
'all' (or specific interfaces) as an option.

See https://github.com/openwrt/packages/pull/29607#discussion_r3463553192

Signed-off-by: Daniel F. Dickinson <redacted>
net/nut/files/nut-monitor.init
net/nut/files/nut-server.init
net/nut/files/nut-service.sh.functions
net/nut/files/nut_monitor
net/nut/files/nut_server

index 9383950c1a894fa17c827a80abe70939071d8782..6de2ba18a686f54972ba59774da16b383d178f03 100644 (file)
@@ -92,7 +92,7 @@ service_preconditions() {
                fi
 
                build_config || return 1
-               interface_triggers "check_interface_up" || return 1
+               interface_triggers "check_interface_up" "upsmon" || return 1
                return 0
                ;;
        *)
@@ -211,6 +211,8 @@ service_triggers() {
 
        config_get interface_reload_delay upsmon interface_reload_delay $DEFAULT_PROCD_INTERFACE_RELOAD_DELAY
 
+       # We do not pass an instance name as the nut-monitor initscript does not need
+       # an additional instance argument
        interface_triggers "add_trigger" "upsmon" "$interface_reload_delay" "nut-monitor" || {
                log_error_exit "Failed to add interface triggers" nut-monitor nut-monitor
        }
index ad4af958f522bd2a1cce835fdcce57a13e393ab6..1a593f7e5ee0c3cba2f95e557d84c19ae9b094b4 100644 (file)
@@ -256,7 +256,7 @@ service_preconditions() {
 
                case $ret in
                0)
-                       interface_triggers "check_interface_up" || should_start_srv=false
+                       interface_triggers "check_interface_up" "upsd" || should_start_srv=false
                        ;;
                *)
                        should_start_srv=false
@@ -269,7 +269,7 @@ service_preconditions() {
 
                case $ret in
                0 | 2)
-                       interface_triggers "check_interface_up" || should_stop_srv=true
+                       interface_triggers "check_interface_up" "upsd" || should_stop_srv=true
                        ;;
                *)
                        should_stop_srv=true
index 44cba46cea7323eb748ecde86861b6028bba8409..fda69ce608260e2f95cf59c4ea4eaf7480c48f33 100644 (file)
@@ -278,7 +278,9 @@ interface_triggers() {
        local section="$2"
        local interface_reload_delay="${3:-$DEFAULT_PROCD_INTERFACE_RELOAD_DELAY}"
        local initscript="$4"
-       local daemon="$5"
+       if [ $# -ge 4 ]; then
+               shift 4
+       fi
        local interfaces interface
        local have_up_interface
        local trigger_failed
@@ -289,7 +291,7 @@ interface_triggers() {
        # We do not need to log or otherwise 'notice' other actions
        case "$action" in
        add_trigger)
-               if [ -n "$interfaces" ]; then
+               if [ -n "$interfaces" ] && [ "$interfaces" != "all" ]; then
                        set -f
                        trigger_failed="false"
                        # interfaces is deliberately unquoted so we get word-splitting for
@@ -297,21 +299,23 @@ interface_triggers() {
                        for interface in $interfaces; do
                                # We use the variadic third and fourth parameters of procd_add_interface_trigger to
                                # restart instead of reload on interface up/down events. Additionally the variadic
-                               # fourth and fifth parameters of procd_add_interface_trigger are passed through to
-                               # the <script>, so the trigger action becomes e.g. /etc/init.d/<script> restart "$daemon".
-                               procd_add_interface_trigger "interface.*.up" "$interface" "/etc/init.d/$initscript" "restart" "$daemon" || trigger_failed="true"
+                               # fifth and parameters of procd_add_interface_trigger are passed through to
+                               # the <script>, so the trigger action becomes e.g. /etc/init.d/<script> restart <variadic_vars>.
+                               procd_add_interface_trigger "interface.*.up" "$interface" "/etc/init.d/$initscript" "restart" "$@" || trigger_failed="true"
                        done
                        set +f
                        if [ "$trigger_failed" = "true" ]; then
                                return 1
                        fi
-               else
+               elif [ "$interfaces" = "all" ]; then
                        # Add a restart trigger on any interface's up status changing
-                       procd_add_raw_trigger "interface.*.up" "$interface_reload_delay" "/etc/init.d/$initscript" "restart" || return 1
+                       procd_add_raw_trigger "interface.*.up" "$interface_reload_delay" "/etc/init.d/$initscript" "restart" "$@" || return 1
+               else
+                       return 0 # don't react to interface status
                fi
                ;;
        check_interface_up)
-               if [ -n "$interfaces" ]; then
+               if [ -n "$interfaces" ] && [ "$interfaces" != "all" ]; then
                        set -f
                        have_up_interface="false"
                        for interface in $interfaces; do
@@ -322,7 +326,7 @@ interface_triggers() {
                                log_msg "None of the trigger interfaces are up." "nut-service.sh" "nut-service" "notice"
                                return 1
                        fi
-               else
+               elif [ "$interfaces" = "all" ]; then
                        # Return true if any interface is up
                        # -q for jsonfilter only suppress error output, not messages on
                        # stdout, redirect to >/dev/null is needed to avoid all output
@@ -331,6 +335,8 @@ interface_triggers() {
                        fi
                        log_msg "No interfaces are up." "nut-service.sh" "nut-service" "notice"
                        return 1
+               else
+                       return 0 # don't depend on interface status
                fi
                ;;
        esac
index ce9302dbb515caca9a045d403d0068b765ca94c7..088cd7bdef011c1e201cdcf9fb8ff587f8121dfb 100644 (file)
@@ -34,6 +34,7 @@
 #      option debugmin 0
 #      option defaultnotify SYSLOG
 # option interface_reload_delay 3000 # in milliseconds
+# option triggerlist all # not configured by default
 
 #config monitor
 #      option type primary
index fa255b0be259e85fe21d2aaed5c6d38a3f8dfe65..9d62f63ea15dc1dbb3631a8d1ffb6c5880279a40 100644 (file)
@@ -8,14 +8,14 @@
 # permissions to access the UPS device(s)
 
 # example USB UPS configuration
-#      config driver 'upsname'
-#              option driver usbhid-ups
-#              option port auto
-#              option productid 12ab # USB 4-digit hex productId
-#              option vendorid 34cd # USB 4-digit hex vendorId
+#config driver 'upsname'
+#      option driver usbhid-ups
+#      option port auto
+#      option productid 12ab # USB 4-digit hex productId
+#      option vendorid 34cd # USB 4-digit hex vendorId
 
 # Configuration for UPS connected to serial-USB
-#              option enable_usb_serial 0
+#      option enable_usb_serial 0
 
 
 #config user
@@ -36,6 +36,7 @@
 #      option statepath /var/run/nut
 #      option maxconn 1024
 #      option runas nut
-# option interface_reload_delay 3000 # in milliseconds
+#      option interface_reload_delay 3000 # in milliseconds
 # NB: certificates only apply to SSL-enabled version
-#       option certfile /usr/local/etc/upsd.pem
+#      option certfile /usr/local/etc/upsd.pem
+# option triggerlist all # not configured by default
git clone https://git.99rst.org/PROJECT