The officially official Devuan Forum!

You are not logged in.

#1 2017-01-18 18:13:48

sgage
Member
Registered: 2016-12-01
Posts: 339  

How to make the 'sleep' button work if yours doesn't

How to make the 'sleep' button work if yours doesn't

One small issue that I'd been having with Devuan Jessie since I first started using it last October was that the sleep button didn't do anything. The sleep button works fine in Debian Jessie, and I suspect that upower now expects some systemd component or other. BTW, this is an ancient (2008) Compaq Presario, Dual Pentium @ 2 GHz, 4 GB RAM rig. It runs beautifully.

Typing 'sudo pm-suspend' in a terminal worked fine, so I knew that the basic sleep functionality was there. At the suggestion of ralph.ronnquist in the Hardware and System Configuration forum I decided to see if I could come up with an acpi event handler to invoke a script to run pm-suspend.

First I wanted to confirm that the sleep button was indeed generating an acpi event, so I ran acpi_listen and pressed the sleep button. Sure enough, it showed 'button/sleep SBTN 00000080 00000000 K'.

Then I went to /etc/acpi/events to make a handler for this event. There was one there already for the power button (powerbtn-acpi-support), so I just copied and modified it for my sleep button, cleverly named 'sleepbtn-acpi-support', containing the following:

event=button[ /]sleep
action=/etc/acpi/sleepbtn-acpi-support.sh

Then I simply made the sleepbtn-acpi-support.sh script in /etc/acpi, to whit:

#!/bin/sh

# This script calls pm-suspend when the sleep button has been
# pressed.

	# Normal handling.
	/usr/sbin/pm-suspend

That's it. Reboot, or restart the acpi daemon, and voila! A press of the sleep button now sends my computer to sleep! I had the same issue with Devuan Ascii, and the same fix applies.

Of course, now you know how to make the sleep button do whatever you want ;-)

Offline

#2 2017-01-23 20:38:03

ralph.ronnquist
Administrator
From: Clifton Hill, Victoria, AUS
Registered: 2016-11-30
Posts: 1,106  

Re: How to make the 'sleep' button work if yours doesn't

It's worth to note that some buttons generate many events, with different arguments. E.g., my lid button has "open" or "close" as (third) arguments . The script (or the recognition rule) will then need to distinguish appropriately, to get the right thing done for the right event(s).

Offline

#3 2017-04-04 20:37:34

malinas
Member
Registered: 2017-02-21
Posts: 12  

Re: How to make the 'sleep' button work if yours doesn't

A slightly more complete solution

First, I commented out /etc/acpi/events/powerbtn-acpi-support:

#event=button[ /]power
#action=/etc/acpi/powerbtn-acpi-support.sh

This ensures that my laptop doesn't shutdown (or do anything special) when I press on the power button by mistake (it happens...).

Then I wrote a generic handler in /etc/acpi/events/default:

event=.*
action=/etc/acpi/default.sh %e

This is going to intercept every ACPI event and call a single script with all available arguments. I do not understand the design decision behind the ACPI daemon, with this concept of event files calling scripts, that tend to be so short and to multiply, so I prefer to put all the logic in a single script. Feel free to do it your own way smile

Finally, the file where the magic happens, /etc/acpi/default.sh:

#!/bin/sh

# log every event in /var/log/messages (can be commented later on)
logger "ACPI event $*"

case "$1" in
    button/sleep)
        [ $2 = "SBTN" ] && pm-suspend
    ;;
    button/lid)
        [ $2 = "LID" ] && [ $3 = "close" ] && pm-suspend
    ;;    
esac

The actual values on someone else's system could be different, this is why it is convenient to log everything when testing the script.

Also, you do not need to restart your acpid service, you can just reload it (though I don't know whether that makes a real difference):

 # /etc/init.d/acpid reload

Offline

Board footer