nut: Various startup fixes for monitor and server
Various path and permissions fixes to properly allow nut-server and nut-monitor to start properly. Signed-off-by: Daniel F. Dickinson <cshored@thecshore.com>
This commit is contained in:
parent
8ff6a83a54
commit
3b5a8eee84
2 changed files with 39 additions and 26 deletions
|
@ -1,6 +1,6 @@
|
||||||
#!/bin/sh /etc/rc.common
|
#!/bin/sh /etc/rc.common
|
||||||
|
|
||||||
START=60
|
START=51
|
||||||
USE_PROCD=1
|
USE_PROCD=1
|
||||||
UPSMON_C=/var/etc/nut/upsmon.conf
|
UPSMON_C=/var/etc/nut/upsmon.conf
|
||||||
|
|
||||||
|
@ -114,6 +114,8 @@ nut_upsmon_conf() {
|
||||||
|
|
||||||
config_get_bool val "$cfg" forcessl 0
|
config_get_bool val "$cfg" forcessl 0
|
||||||
if [ -n "$val" ]; then echo "FORCESSL $val" >> "$UPSMON_C"; fi
|
if [ -n "$val" ]; then echo "FORCESSL $val" >> "$UPSMON_C"; fi
|
||||||
|
|
||||||
|
havemon=1
|
||||||
}
|
}
|
||||||
|
|
||||||
nut_upsmon_add() {
|
nut_upsmon_add() {
|
||||||
|
@ -138,6 +140,8 @@ nut_upsmon_add() {
|
||||||
system="$system:$port";
|
system="$system:$port";
|
||||||
fi
|
fi
|
||||||
echo "MONITOR $system $powervalue $username $password $type" >> "$UPSMON_C"
|
echo "MONITOR $system $powervalue $username $password $type" >> "$UPSMON_C"
|
||||||
|
|
||||||
|
havems=1
|
||||||
}
|
}
|
||||||
|
|
||||||
build_config() {
|
build_config() {
|
||||||
|
@ -149,19 +153,24 @@ build_config() {
|
||||||
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)" ] && {
|
[ ! -s "$(cat /var/etc/nut/nut.conf)" ] && {
|
||||||
echo "MODE=netclient" >>/var/etc/nut/nut.conf
|
echo "MODE=netclient" >>/var/etc/nut/nut.conf
|
||||||
chmod 640 /var/etc/nut/nut.conf
|
chmod 640 /var/etc/nut/nut.conf
|
||||||
chgrp $(id -gn ${runas:-root}) /var/etc/nut/nut.conf
|
chgrp $(id -gn ${runas:-root}) /var/etc/nut/nut.conf
|
||||||
}
|
}
|
||||||
|
|
||||||
chmod 640 "$UPSMON_C"
|
[ -s "$UPSMON_C" ] && chmod 640 "$UPSMON_C"
|
||||||
chgrp $(id -gn ${runas:-root}) "$UPSMON_C"
|
[ -s "$UPSMON_C" ] && chgrp $(id -gn ${runas:-root}) "$UPSMON_C"
|
||||||
}
|
}
|
||||||
|
|
||||||
start_service() {
|
start_service() {
|
||||||
|
local havemon havems
|
||||||
build_config
|
build_config
|
||||||
procd_open_instance
|
|
||||||
|
[ "$havemon" != 1 ] && return
|
||||||
|
[ "$havems" != 1 ] && return
|
||||||
|
|
||||||
|
procd_open_instance "upsmon"
|
||||||
procd_set_param respawn
|
procd_set_param respawn
|
||||||
procd_set_param stderr 0
|
procd_set_param stderr 0
|
||||||
procd_set_param stdout 1
|
procd_set_param stdout 1
|
||||||
|
@ -172,14 +181,14 @@ start_service() {
|
||||||
reload_service() {
|
reload_service() {
|
||||||
if pgrep upsmon >/dev/null 2>/dev/null; then
|
if pgrep upsmon >/dev/null 2>/dev/null; then
|
||||||
build_config
|
build_config
|
||||||
upsmon -c reload
|
/usr/sbin/upsmon -c reload
|
||||||
else
|
else
|
||||||
stop
|
stop
|
||||||
sleep 1
|
sleep 2
|
||||||
start
|
start_service
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
service_triggers() {
|
service_triggers() {
|
||||||
procd_add_reload_trigger nut_monitor
|
procd_add_reload_trigger "nut_monitor"
|
||||||
}
|
}
|
||||||
|
|
|
@ -117,7 +117,7 @@ build_server_config() {
|
||||||
|
|
||||||
chmod 0640 "$USERS_C"
|
chmod 0640 "$USERS_C"
|
||||||
chmod 0640 "$UPSD_C"
|
chmod 0640 "$UPSD_C"
|
||||||
chmod 0640 /var/etc/nut/nut.conf
|
chmod 0644 /var/etc/nut/nut.conf
|
||||||
|
|
||||||
[ -d "${STATEPATH}" ] || {
|
[ -d "${STATEPATH}" ] || {
|
||||||
mkdir -m 0750 -p "${STATEPATH}"
|
mkdir -m 0750 -p "${STATEPATH}"
|
||||||
|
@ -128,17 +128,14 @@ build_server_config() {
|
||||||
chgrp $(id -gn $RUNAS) "$USERS_C"
|
chgrp $(id -gn $RUNAS) "$USERS_C"
|
||||||
chgrp $(id -gn $RUNAS) "$UPSD_C"
|
chgrp $(id -gn $RUNAS) "$UPSD_C"
|
||||||
fi
|
fi
|
||||||
|
haveserver=1
|
||||||
}
|
}
|
||||||
|
|
||||||
build_driver_config() {
|
build_driver_config() {
|
||||||
local cfg="$1"
|
local cfg="$1"
|
||||||
local runas
|
|
||||||
|
|
||||||
echo "[$cfg]" >>"$UPS_C"
|
echo "[$cfg]" >>"$UPS_C"
|
||||||
|
|
||||||
config_get runas "$cfg" runas "nut"
|
|
||||||
RUNAS="$runas"
|
|
||||||
|
|
||||||
get_write_driver_config "$cfg" driver "usbhid-ups"
|
get_write_driver_config "$cfg" driver "usbhid-ups"
|
||||||
get_write_driver_config "$cfg" port "auto"
|
get_write_driver_config "$cfg" port "auto"
|
||||||
get_write_driver_config "$cfg" mfr
|
get_write_driver_config "$cfg" mfr
|
||||||
|
@ -166,12 +163,18 @@ build_driver_config() {
|
||||||
}
|
}
|
||||||
|
|
||||||
build_config() {
|
build_config() {
|
||||||
|
local RUNAS=nut
|
||||||
|
local STATEPATH=/var/run/nut
|
||||||
|
|
||||||
mkdir -m 0755 -p "$(dirname "$UPS_C")"
|
mkdir -m 0755 -p "$(dirname "$UPS_C")"
|
||||||
rm -f "$UPS_C"
|
rm -f "$UPS_C"
|
||||||
echo "# Config file automatically generated from UCI config" > "$UPS_C"
|
echo "# Config file automatically generated from UCI config" > "$UPS_C"
|
||||||
chmod 0640 "$UPS_C"
|
chmod 0640 "$UPS_C"
|
||||||
|
|
||||||
config_load nut_server
|
config_load nut_server
|
||||||
|
config_foreach upsd_statepath upsd
|
||||||
|
|
||||||
|
config_foreach build_global_driver_config driver_global
|
||||||
config_foreach build_driver_config driver
|
config_foreach build_driver_config driver
|
||||||
[ -n "$RUNAS" ] && chgrp $(id -gn $RUNAS) "$UPS_C"
|
[ -n "$RUNAS" ] && chgrp $(id -gn $RUNAS) "$UPS_C"
|
||||||
|
|
||||||
|
@ -181,26 +184,29 @@ build_config() {
|
||||||
start_driver_instance() {
|
start_driver_instance() {
|
||||||
local cfg="$1"
|
local cfg="$1"
|
||||||
local requested="$2"
|
local requested="$2"
|
||||||
local RUNAS=nut
|
|
||||||
local driver
|
local driver
|
||||||
|
local STATEPATH=/var/run/nut
|
||||||
|
local RUNAS=nut
|
||||||
|
|
||||||
|
[ "$havedriver" != 1 ] && return
|
||||||
|
|
||||||
# If wanting a specific instance, only start it
|
# If wanting a specific instance, only start it
|
||||||
[ "$requested" != "$cfg" ] && [ x"$requested" != x"" ] && return 0
|
[ "$requested" != "$cfg" ] && [ x"$requested" != x ] && return 0
|
||||||
|
|
||||||
mkdir -m 0755 -p "$(dirname "$UPS_C")"
|
mkdir -m 0755 -p "$(dirname "$UPS_C")"
|
||||||
|
|
||||||
[ ! -s "$UPS_C" ] && build_config
|
[ ! -s "$UPS_C" ] && build_config
|
||||||
|
|
||||||
|
|
||||||
# Avoid hotplug inadvertenly restarting driver during
|
# Avoid hotplug inadvertenly restarting driver during
|
||||||
# forced shutdown
|
# forced shutdown
|
||||||
[ -f /var/run/killpower ] && return 0
|
[ -f /var/run/killpower ] && return 0
|
||||||
[ -d /var/run/nut ] && [ -f /var/run/nut/disable-hotplug ] && return 0
|
[ -d /var/run/nut ] && [ -f /var/run/nut/disable-hotplug ] && return 0
|
||||||
|
|
||||||
|
|
||||||
|
config_foreach upsd_statepath upsd
|
||||||
|
|
||||||
if [ -n "$RUNAS" ]; then
|
if [ -n "$RUNAS" ]; then
|
||||||
chown $RUNAS:$(id -gn $RUNAS) "${STATEPATH}"
|
chown $RUNAS:$(id -gn $RUNAS) "${STATEPATH}"
|
||||||
chown $RUNAS:$(id -gn $RUNAS) "$(dirname "$UPS_C")"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
config_get driver "$cfg" driver "usbhid-ups"
|
config_get driver "$cfg" driver "usbhid-ups"
|
||||||
|
@ -213,9 +219,11 @@ start_driver_instance() {
|
||||||
}
|
}
|
||||||
|
|
||||||
start_server_instance() {
|
start_server_instance() {
|
||||||
local RUNAS STATEPATH
|
local RUNAS
|
||||||
build_config
|
build_config
|
||||||
|
|
||||||
|
[ "$haveserver" != 1 ] && return
|
||||||
|
|
||||||
procd_open_instance "upsd"
|
procd_open_instance "upsd"
|
||||||
procd_set_param respawn
|
procd_set_param respawn
|
||||||
procd_set_param stderr 0
|
procd_set_param stderr 0
|
||||||
|
@ -225,30 +233,26 @@ start_server_instance() {
|
||||||
}
|
}
|
||||||
|
|
||||||
start_service() {
|
start_service() {
|
||||||
|
local havedriver haveserver
|
||||||
local STATEPATH=/var/run/nut
|
local STATEPATH=/var/run/nut
|
||||||
|
|
||||||
# Avoid hotplug inadvertenly restarting driver during
|
# Avoid hotplug inadvertenly restarting driver during
|
||||||
# forced shutdown
|
# forced shutdown
|
||||||
[ -f /var/run/killpower ] && return 0
|
[ -f /var/run/killpower ] && return 0
|
||||||
[ -d /var/run/nut ] && [ -f /var/run/nut/disable-hotplug ] && return 0
|
[ -f /var/run/nut/disable-hotplug ] && return 0
|
||||||
|
|
||||||
config_load nut_server
|
config_load nut_server
|
||||||
config_foreach upsd_statepath upsd
|
|
||||||
|
|
||||||
[ -d "${STATEPATH}" ] || {
|
|
||||||
mkdir -m 0750 -p "${STATEPATH}"
|
|
||||||
}
|
|
||||||
|
|
||||||
build_config
|
build_config
|
||||||
config_foreach start_driver_instance driver "$@"
|
config_foreach start_driver_instance driver "$@"
|
||||||
|
|
||||||
[ "$1" != "upsd" ] && [ x"$1" != x"" ] && return 0
|
|
||||||
start_server_instance "upsd"
|
start_server_instance "upsd"
|
||||||
}
|
}
|
||||||
|
|
||||||
reload_service() {
|
reload_service() {
|
||||||
stop
|
stop
|
||||||
sleep 2
|
sleep 2
|
||||||
|
local havedriver haveserver
|
||||||
start
|
start
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue