2 Questions Re UPS Management

Home » CentOS » 2 Questions Re UPS Management
CentOS 27 Comments

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.

question #1:
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 -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.

Question #2:
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!


27 thoughts on - 2 Questions Re UPS Management

  • Fred Smith wrote:

    Interesting…. I haven’t observed this behavior; certainly not on headless servers, though most are on UPSes; nor, when I had a working UPS
    for my workstation, have I seen it. Are you running gnome or KDE?
    You mean, like apcupsd?

    Thinking about this as I write, I’d guess that it expects the machine
    *receiving* the shutdown to respect the five minute wait. What you might want to do is a sleep 300 before sending the command.


  • Yes, nor “nut” either.

    just to be sure I’m clear: the shutdown command appears to be sent to windows, as I desire. then instead of honoring the “+5” in the local shutdown command it shuts down immediately.

    but if I just run the identical script from a commandline it does exactly what I think it should: (1) tells windows to shut down then (2)
    waits 5 mins before shutting down Linux.

  • Well, factor this in, then:
    the original powerfail entry in inittab was the same as the shutdown command in my script EXCEPT for the lengthy command that makes windows shutdown. It uses exactly the same “shutdown…” command, and as long as that command is inside inittab, when powerfail occurs, the pause also occurs. only when I move it out to the external script does the pause fail to happen.

  • Fred Smith wrote:

    # 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 -U %
    /sbin/shutdown -f -h +5 “Power Failure; System Shutting Down”

    Hoold on thar: I just had some thoughts, and went back to look at your script… then the man page, then shutdown –help.

    What’s that undocumented -f do?


  • This is a CentOS-5 system. here’s an excerpt from its man page:

    /sbin/shutdown [-t sec] [-arkhncfFHP] time [warning-message]



    -f Skip fsck on reboot.

    The -f flag means \u2018reboot fast\u2019. This only creates an advisory file /fastboot which can be tested
    by the system when it comes up again. The boot rc file can test if this file is present, and
    decide not to run fsck(1) since the system has been shut down in the proper way. After that, the
    boot process should remove /fastboot.

  • I originally did that (I think my original posting mentioned that) without the backslashes, but when run it got an error message about line too long or something similar, so that’s why I tried making it an external script.

    Ah, I see you used “&&” whereas I just used a semicolon separator. wonder if it would make any difference…. (I understand that the “&&”
    causes the second command to be skipped if the first one fails, while the semicolon keeps it as two independent commands.)

    I don’t expect to be back there til Monday, but I’ll try some of these variants when I get there. (I could VPN in and try it, but if something goes haywire, then I’m scrod for remote access.)

  • GNOME features power management software that handles common battery support. The same software manages laptops that operate on battery and desktop PCs with a UPS.

    If you run the script manually, you should expect to see the Windows PC
    shut down, then the Linux machine after 5 minutes, and the UPS should shut down with the Linux host. Is that what happens?

    It sounds like you have the Linux host on the UPS “master” port, which typically has to be configured specifically to behave the way that you describe. One option that you might have is to configure the UPS not to turn off along with the master port, particularly if you have more than one PC on it. Master ports should only be used if the UPS is powering a single PC and its peripherals (external disks, etc).

    If you’re not using a master port, then it sounds like the UPS is simply draining too quickly. If you have a 500Va UPS, it’s probably not going to support two PCs for five minutes. Without knowing more about the UPS
    capacity and its load, we can only speculate, but it may be that GNOME
    is firing off the system shutdown script on power loss, then firing another shutdown when the available power reaches a critically low threshold, and then everything shutting off when there’s no longer juice to support it (especially if you’re testing this without giving the UPS
    24 hours to fully charge up).

    Try turning off the Windows host and then pulling the UPS off of line power. See how everything behaves when only the Linux host is running on the UPS.

    It won’t.

    Yes, I believe you’re doing it correctly.

    If you want the systems to shut down whether or not you’re logged in, you’d need to install NUT and configure it to manage the UPS, and configure GNOME to not do so.

    If you’re logged in, yes. If you’re not logged in, nothing is monitoring the UPS.

    GNOME! It “just works”!

    Yeah, if you want a system that you have more control over, use NUT
    rather than GNOME. You’ll gain the added benefit of UPS support when no user is logged in at the console.

  • For the love of god, don’t do that! Using “&&,” if the Windows host isn’t available, and “net” exits with an error code, the local system won’t be instructed to shut down.

  • Yes. exactly that.

    And, if I use the original inittab entry (which is just the shutdown command for linux, with a “+3” in it) it waits 3 minutes then shuts down.

    I dunno what a “master port” is,… there’s only one place to connect the USB cable to the UPS.

    No, it’s a 1500VA (900 W) ups. it powers two PCs, one monitor and one teeny little network switch. normal load is between 190-200 watts. It’s got plenty of oomph to power both systems for at least 15 minutes.

    so my puzzle remains: why does shutdown not honor the “+5” when it’s part of a separate script, but does when it’s not?

    You think this mechanism only works when logged in? (I have no idea, I’m not doubting you, it’s simply a thought I hadn’t had–yet).

    but that’s probably not a problem, I’m logged in there pretty much
    24 hours a day.

    the C6 system is a personal desktop, at home, and it too is logged in most of the time. Last time I looked at nut, I found too many things I had to know in order to configure it that I didn’t know, like it wasn’t clear which nut device driver was correct for the tripplite UPS I had at the time, and some of the configurations (as far as I recall,… it’s been several years) depended on which device it was. So after messing with it a while, and it not working, I just gave it up.

    Thanks for the info, though.


  • OK.

    The master port is a power port on the UPS. If configured to do so, the UPS will shut off all power ports when the device on the master port shuts off.

    If you’re actually using a master port, the Windows host and all other devices would be immediately turned off every time you power down the Linux host. That’s one way to determine whether or not you are.

    However, if you’re not, then I’m not sure why the UPS would ever turn off. I’m almost completely certain that GNOME’s power management cannot power off the UPS when the system halts. That feature is common to business class UPS management software, but not GNOME.

    That’s still a useful test, as is just shutting down the Linux host to see if the other equipment is turned off when the Linux host shuts off.

    My first guess would be that either the powerfail script is being executed as part of a shutdown, or that the powerfail script is being executed in addition to a shutdown.

    I don’t use GNOME power management, so I can’t say that I’ve tested it.
    However, everything that I’ve read indicates that it only functions in the user shell. gdm’s session may not run the power management code, or may not be configured to do anything on a low power state.

    For USB attached UPSs, it’s pretty straightforward.


    driver = usbhid-ups
    port = auto

    … follow the examples to create an admin user, set passwords. I
    frequently use “uuidgen” to create passwords for these.

    password = @PASSWORD@
    allowfrom = localhost
    actions = SET
    instcmds = ALL
    upsmon master

    MONITOR apc@localhost 1 admin @PSAASWORD@ master

  • Gordon, thanks for the additional info. I’ll experiment with these things as time permits, and if I learn anything interesting I’ll generate a reply at that time.


  • I hope to see it. :)

    That’s not really necessary. It’s all in the archives already, and those have linked messages and threaded indexes for easy navigation. It’s better to trim.

    Thanks, Fred.

  • Do you have a specific example of a UPS that is explicitly documented to be configurable in this fashion? A quick DDG search didn’t turn up anything for me (though I admit I didn’t put huge effort in).


  • I’ll toss in the anecdotal data point that in umpteen years of dealing with IT stuffs, I’ve not seen any UPS’s so configured.

  • the one in question (on the C5 box in my office) has no such labeling on its battery-backed-up outlets, so if it has a master outlet, it’s undocumented.

    I recall, from reading docs in either nut, or the apc package for linux (don’t recall which) that many USB UPSes do have signalling between the UPS and the computer to tell the UPS to shut itself off when the system has gone offline. So, I’ve been assuming that’s what is happening in my case.

  • That’s handled by /etc/init.d/halt. It only happens if you have nut or APC’s software installed and configured. Take a look at the script, it’s the last thing that happens if UPS management software is present.
    If not, then the system will try kexec or halt.

  • Great, thanks! I wouldn’t see me using that feature myself, but I can see where a lot of people who really just want a desktop connected to a UPS might find it helpful.

    The referenced manual seems to imply that the default setting for the master outlet is disabled, so it may not be the issue the OP is having.


  • Yeah, but I’m not sure why else the UPS would shut off. CentOS won’t do that unless nut or apcupsd is installed and configured.