Lee Damon
2018-Feb-01 22:14 UTC
[Nut-upsuser] CentOS 7, systemd, nut-monitor, and failing to shut down the UPS
I've been wrasslin' with a problem on a CentOS 7 host that I'm using as my main NUT server. When the battery gets low while the server is shutting down it is supposed to signal the UPS to shut down as well. This is clear, well documented, and The Right and True Thing to Do<tm>. However, the default scripts provided in the EPEL RPM aren't actually doing it. The host halts as expected but the UPS never gets the message. After a lot of false leads and frustration I narrowed it down to the /usr/lib/systemd/system-shutdown/nutshutdown script. It _appears_ that the calls to "upsmon -K" and "upsdrvctl shutdown" can't actually do anything because the USB device is in use. This _implies_ to me that nut-driver is still running, even this late in the shutdown process. I've "fixed" this problem by modifying the nutshutdown script: #!/bin/sh # stop nut driver to free up access to the device /sbin/systemctl stop nut-driver # make sure it has time to die sleep 2 # check to see if we need to actually shutdown the UPS then do it /usr/sbin/upsmon -K >/dev/null 2>&1 && /usr/sbin/upsdrvctl shutdown This appears to have fixed the problem but it leaves me worried that I've missed something critical and it's going to haunt me later. Is anyone else on this list using the combination of NUT, systemd, and CentOS/RHEL 7? How did/do you solve this problem? thanks, nomad
Roger Price
2018-Feb-02 13:07 UTC
[Nut-upsuser] CentOS 7, systemd, nut-monitor, and failing to shut down the UPS
On Thu, 1 Feb 2018, Lee Damon wrote:> I've "fixed" this problem by modifying the nutshutdown script: > #!/bin/sh > # stop nut driver to free up access to the device > /sbin/systemctl stop nut-driver > # make sure it has time to die > sleep 2 > # check to see if we need to actually shutdown the UPS then do it > /usr/sbin/upsmon -K >/dev/null 2>&1 && /usr/sbin/upsdrvctl shutdownI don't have NUT + systemd + CentOS/RHEL, but I'm confused by your script. "upsdrvctl" is a front end to your driver. You are sending a command via upsdrvctl and via your driver _after_ you have stopped the driver? And it works?> How did/do you solve this problem?I don't use the nutshutdown script, but rather a systemd service unit which is called much earlier in the shutdown process. This allows logging of the action. It's described in Appendix B.2 at http://rogerprice.org/NUT/ConfigExamples.A5.pdf#subsection.B.2 Roger
Charles Lepple
2018-Feb-02 14:00 UTC
[Nut-upsuser] CentOS 7, systemd, nut-monitor, and failing to shut down the UPS
On Feb 2, 2018, at 8:07 AM, Roger Price wrote:> >> # check to see if we need to actually shutdown the UPS then do it >> /usr/sbin/upsmon -K >/dev/null 2>&1 && /usr/sbin/upsdrvctl shutdown > > I don't have NUT + systemd + CentOS/RHEL, but I'm confused by your script. "upsdrvctl" is a front end to your driver. You are sending a command via upsdrvctl and via your driver _after_ you have stopped the driver? And it works?Roger, "upsdrvctl shutdown" does not talk to the running driver - it starts a new copy with the "-k" flag to kill power. https://github.com/networkupstools/nut/blob/v2.7.4/drivers/upsdrvctl.c#L337