|
|
@ -6,56 +6,57 @@ UPSMON_C=/var/etc/nut/upsmon.conf |
|
|
|
|
|
|
|
nut_upsmon_conf() { |
|
|
|
local cfg="$1" |
|
|
|
local RUNAS val optval |
|
|
|
|
|
|
|
echo "# Config file automatically generated from UCI config" > $UPSMON_C |
|
|
|
echo "# Config file automatically generated from UCI config" > "$UPSMON_C" |
|
|
|
|
|
|
|
config_get runas "$cfg" runas "nut" |
|
|
|
[ -n "$runas" ] && echo "RUN_AS_USER $runas" >> $UPSMON_C |
|
|
|
config_get RUNAS "$cfg" runas "nutmon" |
|
|
|
[ -n "$RUNAS" ] && echo "RUN_AS_USER $RUNAS" >> "$UPSMON_C" |
|
|
|
runas=$RUNAS |
|
|
|
|
|
|
|
config_get val "$cfg" minsupplies 1 |
|
|
|
echo "MINSUPPLIES $val" >> $UPSMON_C |
|
|
|
echo "MINSUPPLIES $val" >> "$UPSMON_C" |
|
|
|
|
|
|
|
config_get val "$cfg" shutdowncmd "/sbin/halt" |
|
|
|
echo "SHUTDOWNCMD \"$val\"" >> $UPSMON_C |
|
|
|
config_get val "$cfg" shutdowncmd "/usr/sbin/nutshutdown" |
|
|
|
echo "SHUTDOWNCMD \"$val\"" >> "$UPSMON_C" |
|
|
|
|
|
|
|
config_get val "$cfg" notifycmd |
|
|
|
[ -n "$val" ] && echo "NOTIFYCMD \"$val\"" >> $UPSMON_C |
|
|
|
[ -n "$val" ] && echo "NOTIFYCMD \"$val\"" >> "$UPSMON_C" |
|
|
|
|
|
|
|
config_get val "$cfg" pollfreq 5 |
|
|
|
echo "POLLFREQ $val" >> $UPSMON_C |
|
|
|
echo "POLLFREQ $val" >> "$UPSMON_C" |
|
|
|
|
|
|
|
config_get val "$cfg" pollfreqalert 5 |
|
|
|
echo "POLLFREQALERT $val" >> $UPSMON_C |
|
|
|
echo "POLLFREQALERT $val" >> "$UPSMON_C" |
|
|
|
|
|
|
|
config_get val "$cfg" hostsync 15 |
|
|
|
echo "HOSTSYNC $val" >> $UPSMON_C |
|
|
|
echo "HOSTSYNC $val" >> "$UPSMON_C" |
|
|
|
|
|
|
|
config_get val "$cfg" deadtime 15 |
|
|
|
echo "DEADTIME $val" >> $UPSMON_C |
|
|
|
echo "DEADTIME $val" >> "$UPSMON_C" |
|
|
|
|
|
|
|
config_get val "$cfg" powerdownflag /var/run/killpower |
|
|
|
echo "POWERDOWNFLAG $val" >> $UPSMON_C |
|
|
|
echo "POWERDOWNFLAG /var/run/killpower" >> "$UPSMON_C" |
|
|
|
|
|
|
|
config_get val "$cfg" onlinemsg |
|
|
|
[ -n "$val" ] && echo "NOTIFYMSG ONLINE \"$val\"" >> $UPSMON_C |
|
|
|
[ -n "$val" ] && echo "NOTIFYMSG ONLINE \"$val\"" >> "$UPSMON_C" |
|
|
|
config_get val "$cfg" onbattmsg |
|
|
|
[ -n "$val" ] && echo "NOTIFYMSG ONBATT \"$val\"" >> $UPSMON_C |
|
|
|
[ -n "$val" ] && echo "NOTIFYMSG ONBATT \"$val\"" >> "$UPSMON_C" |
|
|
|
config_get val "$cfg" lowbattmsg |
|
|
|
[ -n "$val" ] && echo "NOTIFYMSG LOWBATT \"$val\"" >> $UPSMON_C |
|
|
|
[ -n "$val" ] && echo "NOTIFYMSG LOWBATT \"$val\"" >> "$UPSMON_C" |
|
|
|
config_get val "$cfg" fsdmsg |
|
|
|
[ -n "$val" ] && echo "NOTIFYMSG FSD \"$val\"" >> $UPSMON_C |
|
|
|
[ -n "$val" ] && echo "NOTIFYMSG FSD \"$val\"" >> "$UPSMON_C" |
|
|
|
config_get val "$cfg" commokmsg |
|
|
|
[ -n "$val" ] && echo "NOTIFYMSG COMMOK \"$val\"" >> $UPSMON_C |
|
|
|
[ -n "$val" ] && echo "NOTIFYMSG COMMOK \"$val\"" >> "$UPSMON_C" |
|
|
|
config_get val "$cfg" commbadmsg |
|
|
|
[ -n "$val" ] && echo "NOTIFYMSG COMMBAD \"$val\"" >> $UPSMON_C |
|
|
|
[ -n "$val" ] && echo "NOTIFYMSG COMMBAD \"$val\"" >> "$UPSMON_C" |
|
|
|
config_get val "$cfg" shutdownmsg |
|
|
|
[ -n "$val" ] && echo "NOTIFYMSG SHUTDOWN \"$val\"" >> $UPSMON_C |
|
|
|
[ -n "$val" ] && echo "NOTIFYMSG SHUTDOWN \"$val\"" >> "$UPSMON_C" |
|
|
|
config_get val "$cfg" replbattmsg |
|
|
|
[ -n "$val" ] && echo "NOTIFYMSG REPLBATT \"$val\"" >> $UPSMON_C |
|
|
|
[ -n "$val" ] && echo "NOTIFYMSG REPLBATT \"$val\"" >> "$UPSMON_C" |
|
|
|
config_get val "$cfg" nocommmsg |
|
|
|
[ -n "$val" ] && echo "NOTIFYMSG NOCOMM \"$val\"" >> $UPSMON_C |
|
|
|
[ -n "$val" ] && echo "NOTIFYMSG NOCOMM \"$val\"" >> "$UPSMON_C" |
|
|
|
config_get val "$cfg" noparentmsg |
|
|
|
[ -n "$val" ] && echo "NOTIFYMSG NOPARENT \"$val\"" >> $UPSMON_C |
|
|
|
[ -n "$val" ] && echo "NOTIFYMSG NOPARENT \"$val\"" >> "$UPSMON_C" |
|
|
|
|
|
|
|
notifylist() { |
|
|
|
local value="$1" |
|
|
@ -85,34 +86,34 @@ nut_upsmon_conf() { |
|
|
|
val="" |
|
|
|
config_list_foreach "$cfg" defaultnotify notifylist |
|
|
|
default="$optval" |
|
|
|
echo "NOTIFYFLAG ONLINE $(setnotify "$cfg" onlinenotify)" >> $UPSMON_C |
|
|
|
echo "NOTIFYFLAG ONBATT $(setnotify "$cfg" onbattnotify)" >> $UPSMON_C |
|
|
|
echo "NOTIFYFLAG LOWBATT $(setnotify "$cfg" lowbatnotify)" >> $UPSMON_C |
|
|
|
echo "NOTIFYFLAG FSD $(setnotify "$cfg" fsdnotify)" >> $UPSMON_C |
|
|
|
echo "NOTIFYFLAG COMMOK $(setnotify "$cfg" commoknotify)" >> $UPSMON_C |
|
|
|
echo "NOTIFYFLAG COMMBAD $(setnotify "$cfg" commbadnotify)" >> $UPSMON_C |
|
|
|
echo "NOTIFYFLAG SHUTDOWN $(setnotify "$cfg" shutdownnotify)" >> $UPSMON_C |
|
|
|
echo "NOTIFYFLAG REPLBATT $(setnotify "$cfg" repolbattnotify)" >> $UPSMON_C |
|
|
|
echo "NOTIFYFLAG NOCOMM $(setnotify "$cfg" nocommnotify)" >> $UPSMON_C |
|
|
|
echo "NOTIFYFLAG NOPARENT $(setnotify "$cfg" noparentnotify)" >> $UPSMON_C |
|
|
|
echo "NOTIFYFLAG ONLINE $(setnotify "$cfg" onlinenotify)" >> "$UPSMON_C" |
|
|
|
echo "NOTIFYFLAG ONBATT $(setnotify "$cfg" onbattnotify)" >> "$UPSMON_C" |
|
|
|
echo "NOTIFYFLAG LOWBATT $(setnotify "$cfg" lowbatnotify)" >> "$UPSMON_C" |
|
|
|
echo "NOTIFYFLAG FSD $(setnotify "$cfg" fsdnotify)" >> "$UPSMON_C" |
|
|
|
echo "NOTIFYFLAG COMMOK $(setnotify "$cfg" commoknotify)" >> "$UPSMON_C" |
|
|
|
echo "NOTIFYFLAG COMMBAD $(setnotify "$cfg" commbadnotify)" >> "$UPSMON_C" |
|
|
|
echo "NOTIFYFLAG SHUTDOWN $(setnotify "$cfg" shutdownnotify)" >> "$UPSMON_C" |
|
|
|
echo "NOTIFYFLAG REPLBATT $(setnotify "$cfg" repolbattnotify)" >> "$UPSMON_C" |
|
|
|
echo "NOTIFYFLAG NOCOMM $(setnotify "$cfg" nocommnotify)" >> "$UPSMON_C" |
|
|
|
echo "NOTIFYFLAG NOPARENT $(setnotify "$cfg" noparentnotify)" >> "$UPSMON_C" |
|
|
|
|
|
|
|
config_get val "$cfg" rbwarntime 43200 |
|
|
|
echo "RBWARNTIME $val" >> $UPSMON_C |
|
|
|
echo "RBWARNTIME $val" >> "$UPSMON_C" |
|
|
|
|
|
|
|
config_get val "$cfg" nocommwarntime 300 |
|
|
|
echo "NOCOMMWARNTIME $val" >> $UPSMON_C |
|
|
|
echo "NOCOMMWARNTIME $val" >> "$UPSMON_C" |
|
|
|
|
|
|
|
config_get val "$cfg" finaldelay 5 |
|
|
|
echo "FINALDELAY $val" >> $UPSMON_C |
|
|
|
echo "FINALDELAY $val" >> "$UPSMON_C" |
|
|
|
|
|
|
|
config_get val "$cfg" certpath |
|
|
|
if [ -n "$val" ]; then echo "CERTPATH $val" >> $UPSMON_C; fi |
|
|
|
if [ -n "$val" ]; then echo "CERTPATH $val" >> "$UPSMON_C"; fi |
|
|
|
|
|
|
|
config_get_bool val "$cfg" certverify 0 |
|
|
|
if [ -n "$val" ]; then echo "CERTVERIFY $val" >> $UPSMON_C; fi |
|
|
|
if [ -n "$val" ]; then echo "CERTVERIFY $val" >> "$UPSMON_C"; fi |
|
|
|
|
|
|
|
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 |
|
|
|
} |
|
|
|
|
|
|
|
nut_upsmon_add() { |
|
|
@ -126,12 +127,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 |
|
|
@ -142,40 +137,49 @@ nut_upsmon_add() { |
|
|
|
if [ -n "$port" ]; then |
|
|
|
system="$system:$port"; |
|
|
|
fi |
|
|
|
echo "MONITOR $system $powervalue $username $password $type" >> $UPSMON_C |
|
|
|
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 |
|
|
|
} |