@ -163,12 +163,39 @@ 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
. /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 reload
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 reload
else
ubus call network.device status | grep -q '"up": true' && return 0
fi
fi
[ "$action" = "add_trigger" ] || return 1
}
start_service() {
local havemon havems
build_config
[ "$havemon" != 1 ] && return
[ "$havems" != 1 ] && return
interface_triggers "check_interface_up" || return
procd_open_instance "upsmon"
procd_set_param respawn
@ -190,5 +217,7 @@ reload_service() {
}
service_triggers() {
confg_load nut_monitor
interface_triggers "add_trigger"
procd_add_reload_trigger "nut_monitor"
}