Awesome - thanks Charles.

-----Original Message-----
From: Charles Lepple [mailto:[email protected]] 
Sent: 31 August 2015 13:37
To: [email protected]
Cc: [email protected]
Subject: Re: [Nut-upsuser] Loses connection after a month or so

On Aug 29, 2015, at 3:11 AM, [email protected] wrote:
> 
> Is there a way (has anyone done it) to reboot (not shutdown!!) the host if 
> communications to the UPS fails – I want to automatically reboot my Pi after 
> a couple of minutes of no communications.
>  
> Has anyone done this? Is there a setting that I can add to monitor nut or the 
> usb subsystem and find out that comms has failed, then run a script to 
> reboot? 
>  
> I note that there is a message “Communications with UPS [email protected] 
> lost” which occurs in /var/daemon.log if that helps!
> 
The "communications lost" message corresponds to the "COMMBAD" event. The list 
of events is here:

   http://www.networkupstools.org/docs/man/upsmon.html#_notify_events

There is a similar event, "NOCOMM", which is probably closer to what you are 
looking for. The `upsmon` daemon checks to see if it has been in the lost-comms 
state for a certain amount of time (controlled by the "NOCOMMWARNTIME" variable 
in upsmon.conf; defaults to five minutes), and if so, upsmon triggers the 
NOCOMM event periodically. In your case, you wouldn't care about the periodic 
nature, but the NOCOMMWARNTIME delay prevents the Pi from rebooting immediately 
upon an error.

You would then set up the NOCOMM event to trigger the EXEC rule (add "+EXEC" to 
the NOTIFYFLAG section of upsmon.conf), and then configure NOTIFYCMD to run a 
script that would reboot the Pi if the first parameter to the script is NOCOMM. 
If you don't already have a NOTIFYCMD, you could skip the script, and reboot 
directly.

It might sound complicated, but if you don't have anything else in upsmon.conf, 
it all boils down to this:

# Reference: http://www.networkupstools.org/docs/man/upsmon.conf.html
NOCOMMWARNTIME 240 # 4 minutes after COMMBAD NOTIFYFLAG NOCOMM SYSLOG+WALL+EXEC 
NOTIFYCMD "/sbin/shutdown -r now 'lost comms to UPS'"

--
Charles Lepple
clepple@gmail





_______________________________________________
Nut-upsuser mailing list
[email protected]
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/nut-upsuser

Reply via email to