From c963f0c2971dcd7876ff9b52d77fe6d17fd040db Mon Sep 17 00:00:00 2001 From: "Daniel F. Dickinson" Date: Mon, 26 Aug 2019 23:43:16 -0400 Subject: [PATCH] nut: Fix upsmon init actions 1) For upsmon start and stop were at wrong position in rc.d 2) Stop needs more than just killing the procd instead but rather needs a stop command to be issued. 3) Interface up/down was causing not to enter a crashloop (we fix this with procd trigger on interface changes). Signed-off-by: Daniel F. Dickinson --- net/nut/files/nut-monitor.init | 46 ++++++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 7 deletions(-) diff --git a/net/nut/files/nut-monitor.init b/net/nut/files/nut-monitor.init index f094a82ba..1e3ab2930 100755 --- a/net/nut/files/nut-monitor.init +++ b/net/nut/files/nut-monitor.init @@ -1,6 +1,7 @@ #!/bin/sh /etc/rc.common -START=51 +START=82 +STOP=28 USE_PROCD=1 UPSMON_C=/var/etc/nut/upsmon.conf @@ -162,6 +163,32 @@ build_config() { [ -s "$UPSMON_C" ] && chgrp $(id -gn ${runas:-root}) "$UPSMON_C" } +interface_triggers() { + local action="$1" + local triggerlist trigger + + config_get triggerlist "upsmon" triggerlist + + . "${IPKG_INSTROOT}"/lib/functions/network.sh + + if [ -n "$triggerlist" ]; then + for trigger in $triggerlist; do + if [ "$action" = "add_trigger" ]; then + procd_add_interface_trigger "interface.*" "$trigger" /etc/init.d/nut-monitor restart + else + network_is_up "$trigger" && return 0 + fi + done + else + if [ "$action" = "add_trigger" ]; then + procd_add_raw_trigger "interface.*.up" 2000 /etc/init.d/nut-monitor restart + else + ubus call network.device status | grep -q '"up": true' && return 0 + fi + fi + [ "$action" = "add_trigger" ] || return 1 +} + start_service() { local runas local havemon havems @@ -169,11 +196,12 @@ start_service() { [ "$havemon" != 1 ] && return [ "$havems" != 1 ] && return + interface_triggers "check_interface_up" || return 0 procd_open_instance "upsmon" - procd_set_param respawn - procd_set_param stderr 0 - procd_set_param stdout 1 + procd_set_param respawn 10 20 6 + procd_set_param stderr 1 + procd_set_param stdout 0 procd_set_param command /usr/sbin/upsmon -D procd_close_instance } @@ -184,12 +212,16 @@ reload_service() { build_config /usr/sbin/upsmon -c reload else - stop - sleep 2 - start_service + restart fi } +stop_service() { + upsmon -c stop +} + service_triggers() { + config_load nut_monitor + interface_triggers "add_trigger" procd_add_reload_trigger "nut_monitor" }