#!/bin/sh /etc/rc.common
-START=51
+START=82
+STOP=28
USE_PROCD=1
UPSMON_C=/var/etc/nut/upsmon.conf
[ -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
[ "$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
}
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"
}