diff --git a/net/nut/files/nut-monitor.init b/net/nut/files/nut-monitor.init index af8140781..34bacfb8e 100755 --- a/net/nut/files/nut-monitor.init +++ b/net/nut/files/nut-monitor.init @@ -126,12 +126,6 @@ nut_upsmon_add() { local password local system - # if UPSMON_C is a symlink we're only doing generated config - [ -L $UPSMON_C ] && { - rm -f $UPSMON_C - nut_upsmon_conf "" - } - config_get upsname "$cfg" upsname config_get hostname "$cfg" hostname localhost config_get port "$cfg" port @@ -145,37 +139,46 @@ nut_upsmon_add() { echo "MONITOR $system $powervalue $username $password $type" >> $UPSMON_C } -start_service() { - mkdir -p "$(dirname "$UPSMON_C")" - chmod 750 "$(dirname "$UPSMON_C")" +build_config() { + local runas + mkdir -m 0750 -p "$(dirname "$UPSMON_C")" config_load nut_monitor - config_foreach nut_upsmon_conf upsmon config_foreach nut_upsmon_add master master config_foreach nut_upsmon_add slave slave - [ -z "$(cat /var/etc/nut/nut.conf)" ] && echo "MODE=netclient" >>/var/etc/nut/nut.conf - - chmod 640 $UPSMON_C - chmod 640 /var/etc/nut/nut.conf - - chown ${runas:-root}:$(id -gn ${runas:-root}) /var/etc/nut - chown ${runas:-root}:$(id -gn ${runas:-root}) /var/etc/nut/nut.conf - chown ${runas:-root}:$(id -gn ${runas:-root}) $UPSMON_C - - [ -d /var/run/nut ] || { - mkdir -m 0750 -p /var/run/nut - chown ${runas:-root}:$(id -gn ${runas:-root}) /var/run/nut + [ -z "$(cat /var/etc/nut/nut.conf)" ] && { + echo "MODE=netclient" >>/var/etc/nut/nut.conf + chmod 640 /var/etc/nut/nut.conf + chgrp $(id -gn ${runas:-root}) /var/etc/nut/nut.conf } - exec $DEBUG /usr/sbin/upsmon $UPSMON_OPTIONS + chmod 640 "$UPSMON_C" + chgrp $(id -gn ${runas:-root}) "$UPSMON_C" } -stop_service() { - exec /usr/sbin/upsmon -c stop +start_service() { + build_config + procd_open_instance + procd_set_param respawn + procd_set_param stderr 0 + procd_set_param stdout 1 + procd_set_param command /usr/sbin/upsmon -D + procd_close_instance } reload_service() { - exec /usr/sbin/upsmon -c reload + if pgrep upsmon >/dev/null 2>/dev/null; then + build_config + upsmon -c reload + else + stop + sleep 1 + start + fi +} + +service_triggers() { + procd_add_reload_trigger nut_monitor } diff --git a/net/nut/files/nut_monitor b/net/nut/files/nut_monitor index 0b71e95cf..1f535b135 100644 --- a/net/nut/files/nut_monitor +++ b/net/nut/files/nut_monitor @@ -51,4 +51,3 @@ # option powervalue 1 # option username upsuser # option password upspassword -