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>
This commit is contained in:
parent
1cd4dcfa99
commit
f6a2a97d2f
2 changed files with 29 additions and 27 deletions
|
@ -126,12 +126,6 @@ nut_upsmon_add() {
|
||||||
local password
|
local password
|
||||||
local system
|
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 upsname "$cfg" upsname
|
||||||
config_get hostname "$cfg" hostname localhost
|
config_get hostname "$cfg" hostname localhost
|
||||||
config_get port "$cfg" port
|
config_get port "$cfg" port
|
||||||
|
@ -145,37 +139,46 @@ nut_upsmon_add() {
|
||||||
echo "MONITOR $system $powervalue $username $password $type" >> $UPSMON_C
|
echo "MONITOR $system $powervalue $username $password $type" >> $UPSMON_C
|
||||||
}
|
}
|
||||||
|
|
||||||
start_service() {
|
build_config() {
|
||||||
mkdir -p "$(dirname "$UPSMON_C")"
|
local runas
|
||||||
chmod 750 "$(dirname "$UPSMON_C")"
|
mkdir -m 0750 -p "$(dirname "$UPSMON_C")"
|
||||||
|
|
||||||
config_load nut_monitor
|
config_load nut_monitor
|
||||||
|
|
||||||
config_foreach nut_upsmon_conf upsmon
|
config_foreach nut_upsmon_conf upsmon
|
||||||
config_foreach nut_upsmon_add master master
|
config_foreach nut_upsmon_add master master
|
||||||
config_foreach nut_upsmon_add slave slave
|
config_foreach nut_upsmon_add slave slave
|
||||||
|
|
||||||
[ -z "$(cat /var/etc/nut/nut.conf)" ] && echo "MODE=netclient" >>/var/etc/nut/nut.conf
|
[ -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
|
||||||
chmod 640 /var/etc/nut/nut.conf
|
chgrp $(id -gn ${runas:-root}) /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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exec $DEBUG /usr/sbin/upsmon $UPSMON_OPTIONS
|
chmod 640 "$UPSMON_C"
|
||||||
|
chgrp $(id -gn ${runas:-root}) "$UPSMON_C"
|
||||||
}
|
}
|
||||||
|
|
||||||
stop_service() {
|
start_service() {
|
||||||
exec /usr/sbin/upsmon -c stop
|
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() {
|
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
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,4 +51,3 @@
|
||||||
# option powervalue 1
|
# option powervalue 1
|
||||||
# option username upsuser
|
# option username upsuser
|
||||||
# option password upspassword
|
# option password upspassword
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue