Hi, trying to figure out how the system manages UPS connections. On both CentOS 5.9 and 6.4, merely plugging in a USB UPS device causes an icon to appear in the top panel, and (at least on 5.9, haven’t yet tested this in 6.4) when the UPS suffers a power failure the system notices and after a bit does a clean shutdown.
All this without installing ANYTHING extra.
one of the UPSes I’m using is a tripplite (now on 6.4 x86_64, but formerly on the same machine with 5.9 i686), the other is a CyberPower UPS on a different 5.9 machine.
in 5.9 there are two entries in /etc/inittab, one for power fail and the other for power restoration. The default setting for the powerfail entry has it doing a shutdown in 2 minutes.
So, I need to tweak it a bit: that UPS powers two computers, the CentOS 5.9
box and a Windows XP box. A little googling showed me how to use Samba tools to tell XP to do a shutdown. That works fine.
but if I add the command for that into the inittab entry I get an error message (when power fails) about the line being too long. So, I created a shellscript that runs both the command to tell XP to go down, followed by the shutdown command that tells CentOS to shut down. I changed the two minute time to 5 minutes to make sure Windoze is all the way down even if it’s busy.
When I run this script from the commandline it works just fine. but when I turn off input power to the UPS it starts the XP shutdown then within without waiting the specified length of time, initiates the shutdown of Linux. Once the shutdown is done, the UPS powers off, thereby killing the not-yet-shutdown windoze box.
# invoked by the poweroff clause in /etc/inittab instead of the command
# originally in that place. This one also shuts down the Windoze box.
net rpc SHUTDOWN -C “System shutting down NOW due to power failure” -f -I 172.19.23.120 -U %
/sbin/shutdown -f -h +5 “Power Failure; System Shutting Down”
and here’s the entry from inittab:
The shellscript does contain “#!/bin/sh” as its first line, but it is currently being invoked simply by the path to the script. when I get back to the office I’ll try changing it to “/bin/bash /etc/powerfail”
to see if that makes a difference, but I kinda don’t expect it to.
So, I’m wondering how the underlying mechanism works, AND if anyone knows how (or even IF) it’s possible to hand inittab a script to run instead of burying the necessary commands directly into the inittab entry.
On the CentOS 6.4 box at home, I haven’t yet tried turning off power to the UPS to see if it actually shuts doown, but given that a UPS icon appears in the panel, and there are settings for what should happen when power fails, I expect it will.
The question here is: how does this magic all work? We no longer have any entries in inittab to manage this, apparently we now use upstart to manage the same things, and I’ve spent some time digging for man pages and looking around for upstart file(s) to find out how such events are handled, and so far I’ve not found anything specifically for a “powerfail” event.
Clues appreciated, thanks all!