Browse Source

nut: Use 'real' procd init for nut-monitor

This fully procdifies nut-monitor, which fixes some issues with
very slow restarts (due to /lib/functions/procd.sh using a very
long delay for non-native scripts doing restart) as well as gives
respawning, etc.

Signed-off-by: Daniel F. Dickinson <cshored@thecshore.com>
lilik-openwrt-22.03
Daniel F. Dickinson 6 years ago
parent
commit
f6a2a97d2f
2 changed files with 29 additions and 27 deletions
  1. +29
    -26
      net/nut/files/nut-monitor.init
  2. +0
    -1
      net/nut/files/nut_monitor

+ 29
- 26
net/nut/files/nut-monitor.init View File

@ -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
}

+ 0
- 1
net/nut/files/nut_monitor View File

@ -51,4 +51,3 @@
# option powervalue 1
# option username upsuser
# option password upspassword

Loading…
Cancel
Save