[Nut-upsuser] Loses connection after a month or so

Charles Lepple clepple at gmail.com
Mon Aug 31 12:36:36 UTC 2015


On Aug 29, 2015, at 3:11 AM, paul at smithp.co.uk 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 Liebert at 192.x.x.x 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 at gmail






More information about the Nut-upsuser mailing list