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. #!/bin/sh # # 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 <myusername>%<mypassword> /sbin/shutdown -f -h +5 "Power Failure; System Shutting Down" and here's the entry from inittab: pf::powerfail:/etc/powerfail 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! Fred -- ------------------------------------------------------------------------------- Under no circumstances will I ever purchase anything offered to me as the result of an unsolicited e-mail message. Nor will I forward chain letters, petitions, mass mailings, or virus warnings to large numbers of others. This is my contribution to the survival of the online community. --Roger Ebert, December, 1996 ----------------------------- The Boulder Pledge -----------------------------
Fred Smith wrote:> 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.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?> > All this without installing ANYTHING extra. >You mean, like apcupsd?> 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.<snip>> 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<snip>> 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.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. <snip> mark
19.3.2013 16:55, Fred Smith kirjoitti:> 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.If you are using the default GNOME desktop, then that's the GNOME Power Manager: http://projects.gnome.org/gnome-power-manager/> The question here is: how does this magic all work?It uses DBus and the UPower service. See: http://upower.freedesktop.org/ -- Markku Kolkka markku.kolkka at iki.fi
On 03/19/2013 07:55 AM, Fred Smith wrote:> All this without installing ANYTHING extra.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.> 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.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.> 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.It won't.> 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.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.> 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.If you're logged in, yes. If you're not logged in, nothing is monitoring the UPS.> The question here is: how does this magic all work?GNOME! It "just works"!> 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.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.