[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: using acpi



On Tue, 2004-07-13 at 10:10 +0200, Bernhard Kleine wrote: 
> Hi,
> since I have already asked some days before whether anybody could
> provide scripts for acpi support e.g. to shut down the screen when the
> cover is closed and since I did not receive any response, 
> 
> I will ask again:
> 
> Is there someone to share his experience using acpi with kernel 2.6.(6)
> and higher?

I'm using 2.6 (currently 2.6.8-rc1) and have been using these scripts:

/etc/acpi/suspend_to_ram.sh
=============================================================
#!/bin/sh
# /etc/acpi/suspend_to_ram.sh
# Initiates a suspend to memory [when the lid is closed]

if ps -Af | grep -q '[k]desktop' && test -f /usr/bin/dcop
then
    dcop --all-users ksmserver ksmserver logout 0 2 0 && exit 0
fi

sync

whereami --syslog --run_from suspend2ram undocked
xscreensaver-command -lock
logger -t "acpi-sleep" "Stopping hotplug"
/etc/init.d/hotplug stop

sleep 1

logger -t "acpi-sleep" "Initiating sleep at `date`"
#echo 3 >/proc/acpi/sleep
echo mem >/sys/power/state

sleep 1
logger -t "acpi-sleep" "Awakening from sleep at `date` ?"

(
  # Run in a subshell so we can finish our job...
  # modprobe e1000
  sleep 2
  /etc/init.d/hotplug start &
  whereami --syslog --run_from resumefromram
) 2>&1 | logger -t 'acpi-sleep' &

=============================================================

/etc/acpi/suspend_to_disk.sh
=============================================================
#!/bin/sh
# /etc/acpi/suspend_to_disk.sh
# Initiates a suspend to disk

if ps -Af | grep -q '[k]desktop' && test -f /usr/bin/dcop
then
    dcop --all-users ksmserver ksmserver logout 0 2 0 && exit 0
fi

whereami --syslog --run_from suspend2disk undocked
# logger -t "acpi-sleep" "Stopping hotplug"
# /etc/init.d/hotplug stop
sleep 1

logger -t "acpi-sleep" "Initiating disk-based suspend at `date`"
echo 4 >/proc/acpi/sleep

sleep 2
logger -t "acpi-sleep" "Awakening from sleep at `date` ?"
sleep 3
whereami --syslog --run_from resumefromdisk

=============================================================

/etc/acpi/suspend_to_disk.sh
=============================================================

=============================================================


And these configuration files...

/etc/acpi/events/lid
=============================================================
# /etc/acpi/events/lid
# This is called when the user closes the lid.

# Optionally you can specify the placeholder %e. It will pass
# through the whole kernel event message to the program you've
# specified.

# We need to react on "button lid.*" and "button/lid.*" because
# of kernel changes.

event=button[ /]lid
action=/etc/acpi/suspend_to_ram.sh

=============================================================

/etc/acpi/events/allevents 
=============================================================
# /etc/acpi/events/allevents
# This is called when any ACPI event happens
# /etc/acpi/log_event is called to log the event

# Optionally you can specify the placeholder %e. It will pass
# through the whole kernel event message to the program you've
# specified.

event=.*
action=/etc/acpi/log_event "%e"
=============================================================


/etc/acpi/events/powerbtn
=============================================================
# /etc/acpi/events/powerbtn
# This is called when the user presses the power button and calls
# /etc/acpi/powerbtn.sh for further processing.

# Optionally you can specify the placeholder %e. It will pass
# through the whole kernel event message to the program you've
# specified.

# We need to react on "button power.*" and "button/power.*" because
# of kernel changes.

event=button[ /]power
action=/etc/acpi/shutdown.sh
=============================================================


In fact I only rarely use the suspend_to_disk script because it doesn't
work reliably.  I suspend to RAM at least twice each day (driving to
work, driving home, plus twice each time I have to go to a meeting out
of the office) - this has worked reliably for many different kernel
versions from 2.6.3 through 2.6.7-mm6. YMMV, of course, because ACPI is
not yet smoothly supported on all laptop models.


How it all works
================

The events directory contains definitions of things that should happen
for various ACPI events.  The names of the files in this directory are
informative, rather than special.  The events that are hooked into are
defined by the:
event=<some regex>
line, which should pattern match against an ACPI event.  I use the
"allevents" definition, along with the "log_event" script to let me
figure out what/whether some specific marked button my keyboard sends,
as far as ACPI goes.

In the case of my laptop, I am able to hook into the "lid" and "power"
buttons (the sleep button doesn't appear to trigger an ACPI event).

When the "event" is matched, the associated "action" is run.  In my case
this means that the suspend_to_ram script is kicked off when I close the
lid.

This script gets fiddled with fairly often, as you can see from all the
crufty bits.  In the middle is the crux, where it echoes "mem"
into /sys/power/state - I sleep for a second immediately after that, or
stuff that's supposed to run at resume will start running before it's
suspended!


Hope this is some help.

Cheers,
					Andrew.

-------------------------------------------------------------------------
Andrew @ Catalyst .Net .NZ  Ltd,  PO Box 11-053, Manners St,  Wellington
WEB: http://catalyst.net.nz/            PHYS: Level 2, 150-154 Willis St
DDI: +64(4)803-2201      MOB: +64(272)DEBIAN      OFFICE: +64(4)499-2267
         All the troubles you have will pass away very quickly.
-------------------------------------------------------------------------

Attachment: signature.asc
Description: This is a digitally signed message part


Reply to: