I have a NAS with a usb plugged UPS on it. I have installed nut client (only the client) on my raspberry to monitor the UPS. I must plug the UPS to the NAS because it's the only device which recognizes my UPS (chinese generic, unfortunately no choice in my country). No way to make it directly work plugged to the raspberry. As I've installed only nut client into my raspberry, /etc/nut was empty. I've created 3 files:
nut.conf
Code: Select all
MODE=netclient
Code: Select all
MONITOR login@nas_ip 1 admin password slave
SHUTDOWNCMD "/sbin/shutdown -h now"
NOTIFYFLAG ONBATT SYSLOG+WALL+EXEC
NOTIFYFLAG ONLINE SYSLOG+WALL+EXEC
NOTIFYCMD "/etc/nut/notifycmd"
Code: Select all
#!/bin/bash
#
# NUT NOTIFYCMD script
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/sbin:/usr/local/bin
trap "exit 0" SIGTERM
if [ "$NOTIFYTYPE" = "ONLINE" ]
then
echo $0: power restored | wall
# curl command to disable my virtual switch "battery"
curl -s "http://ip_domoticz:port/json.htm?type=command¶m=switchlight&idx=XX&switchcmd=Off"
# Cause all instances of this script to exit.
killall -s SIGTERM `basename $0`
fi
if [ "$NOTIFYTYPE" = "ONBATT" ]
then
echo $0: 40 minutes till system powers down... | wall
# curl command to activate my virtual switch "battery"
curl -s "http://ip_domoticz:port/json.htm?type=command¶m=switchlight&idx=XX&switchcmd=On"
# Loop with one second interval to allow SIGTERM reception.
let "n = 2400"
while [ $n -ne 0 ]
do
sleep 1
let "n--"
done
echo $0: commencing shutdown | wall
sleep 10
upsmon -c fsd
fi
But there is a special case: if the raspberry lost connection with the ups when it is on battery, the raspberry shut down almost immediately... I think this is a protection behavior, but i'd like to insert a curl command which sends a sms before shutdown, like "power loss and connexion failure with ups" (i know the command itself, this is not the problem) I know I must add something like "DEADTIME" or "NOTIFYFLAG NOCOMM" or "COMMBAD" in upsmon.conf, but not sure what to choose... And what do i have to add in my "notifycmd" file ?
Thanks