paul at smithp.co.uk
2015-Aug-29 07:11 UTC
[Nut-upsuser] Loses connection after a month or so
Hi, I have a Liebert UPS which I have connected to a FreeNAS Box. I had all sorts of issues making FreeNAS (FreeBSD based) talk to the UPS over USB. My solution seemed to be to buy a Raspberry Pi then connect it to the UPS (works fine), then make my NAS read the UPS status from the Pi over a TCP/IP connection. Convoluted I know, but it works well...for about a month, then it just loses connection. The Raspberry Pi stops communicating with the UPS - rebooting the Pi resolves the issue. I have a couple of things to do (like updating the software on the Pi), which I am hoping might resolve the connection problem but my question is; 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 <mailto:Liebert at 192.x.x.x> lost" which occurs in /var/daemon.log if that helps! It always seems to fall over sometime during the night and then I usually wake up to 80 - 100 email messages from my NAS box saying it has lost the connection. Best Regards, Paul Smith -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.alioth.debian.org/pipermail/nut-upsuser/attachments/20150829/fd3ae419/attachment.html>
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
Awesome - thanks Charles. -----Original Message----- From: Charles Lepple [mailto:clepple at gmail.com] Sent: 31 August 2015 13:37 To: paul at smithp.co.uk Cc: Nut-upsuser at lists.alioth.debian.org Subject: Re: [Nut-upsuser] Loses connection after a month or so 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