Results 1 to 4 of 4
Alright, I've got this idea that really only applies to laptops (I believe).
AND, in particular to laptops like my old Dell Inspiron 6400 with a battery that will power ...
- 08-15-2011 #1Just Joined!
- Join Date
- Nov 2006
- Location
- near Berea, Kentucky (in a tipi)
- Posts
- 34
"New" Idea: maybe belongs in programming forum...
Alright, I've got this idea that really only applies to laptops (I believe).
AND, in particular to laptops like my old Dell Inspiron 6400 with a battery that will power the machine for a few (like 5) minutes, at most.
(BTW, openSUSE 11.4 Xfce, not that it matters.)
In /etc/inittab there are the following lines:
pf:
owerwait:/etc/init.d/powerfail start
pn:
owerfailnow:/etc/init.d/powerfail now
I know these are there to allow UPS software to tell init to do a shutdown if and when the power fails. How does that work? What triggers these events?
What I'd like is for the pf: line to get kicked if the AC power fails, giving the machine time to shutdown gracefully.
Does anyone know how to write something that does that? Alternatively, of course, a script could just execute shutdown (provided it had enough privilege.) So, really, the question is, how do I find out if we're running on AC, or get a poke when that ceases to be the case?
What I'm envisioning is a bash/perl/python script or C program that runs as a daemon, gets the signal from APM or ACPI and either uses inittab or not to shut the machine down.
Any pointers would be greatly appreciated. Thanks!
- 08-17-2011 #2Just Joined!
- Join Date
- Nov 2006
- Location
- near Berea, Kentucky (in a tipi)
- Posts
- 34
Okay, having received no reply... and after a bit more research, here's what I tried:
$ cat /etc/acpi/events/battery
event=battery.*
action=/etc/acpi/actions/battery.sh
$ cat /etc/acpi/actions/battery.sh
#!/bin/bash
# ac/battery event handler
#
status=`awk '/^state: / { print $2 }' /proc/acpi/ac_adapter/AC/state`
if [ "$status" = "off-line" ]
then
## following line still contains -k option (just kidding...)
/sbin/shutdown -k now "AC Adapter Unplugged... Shutting system down now!!!!"
else
#
/sbin/shutdown -c now "AC Power Restored... System continues"
fi
and:
$ ls -l /etc/acpi/actions/battery.sh
-rwxr-xr-x 1 root root 626 Aug 16 17:43 /etc/acpi/actions/battery.sh
/var/log/messages shows acpid getting the correct number of rules.
I pull the plug and NOTHING HAPPENS.
I run the battery.sh script explicitly (as root) and it complains it can't find the pid of running shutdown (fair enough since there isn't one.)
I can also test the awk line on the cl and it works fine.
so: acpid isn't triggering the script.
How to debug?
- 08-18-2011 #3Linux Guru
- Join Date
- May 2011
- Posts
- 1,818
Have you tried running the acpid daemon in the foreground, with the debug flag on?
maybe that will turn up something.Code:service acpid stop acpid -d -f
- 08-18-2011 #4Just Joined!
- Join Date
- Nov 2006
- Location
- near Berea, Kentucky (in a tipi)
- Posts
- 34
"New" idea: SOLVED
That was a very useful reply, thank you!
I found that acpid -f -d -l was needed to get acpid to 'log' to STDERR. That showed me that the 'event' was not a battery event, but an 'ac_adapter' event.
So:
and;Code:$ cat /etc/acpi/events/ac_adapter event=ac_adapter.* action=/etc/acpi/actions/ac_adapter.sh
works beautifully!Code:$ cat /etc/acpi/actions/ac_adapter.sh #!/bin/bash # ac/battery event handler # status=`awk '/^state: / { print $2 }' /proc/acpi/ac_adapter/AC/state` if [ "$status" = "off-line" ] then /sbin/shutdown -h now "AC Adapter Unplugged... Shutting system down now!!!!" else /sbin/shutdown -c now "AC Power Restored... System continues" fi
Thanks again!
Daniel


Reply With Quote
