You are not logged in.

#1 2012-10-17 18:30:49

xorgx3
Member
From: Poland
Registered: 2011-11-29
Posts: 197

Hibernate when i press power button

Hi,
I want hibernate my system when i will press power button. But it didn't working on acpid.
Here is my handler.sh:

#!/bin/bash
# Default acpi script that takes an entry for all actions

case "$1" in
    button/power)
        case "$2" in
           PWRF)   logger "PowerButton pressed: $2" 
		    systemctl suspend;;
           *)      logger "ACPI action undefined: $2" ;;
        esac
        ;;
    button/sleep)
        case "$2" in
            SLPB|SBTN)
                sleep 2 && systemctl suspend
                ;;
            *)
                logger "ACPI action undefined: $2"
                ;;
        esac
        ;;
    ac_adapter)
        case "$2" in
            AC|ACAD|ADP0)
                case "$4" in
                    00000000)
                        logger 'AC unpluged'
                        ;;
                    00000001)
                        logger 'AC pluged'
                        ;;
                esac
                ;;
            *)
                logger "ACPI action undefined: $2"
                ;;
        esac
        ;;
    battery)
        case "$2" in
            BAT0)
                case "$4" in
                    00000000)
                        logger 'Battery online'
                        ;;
                    00000001)
                        logger 'Battery offline'
                        ;;
                esac
                ;;
            CPU0)
                ;;
            *)  logger "ACPI action undefined: $2" ;;
        esac
        ;;
    button/lid)
        case "$3" in
            close)
                sleep 2 && systemctl suspend
                ;;
            open)
                logger 'LID opened'
                ;;
            *)
                logger "ACPI action undefined: $3"
                ;;
    esac
    ;;
    *)
        logger "ACPI group/action undefined: $1 / $2"
        ;;
esac

# vim:set ts=4 sw=4 ft=sh et:

Suspend working for close lid and for sleep button, but not working for power button. Now if i press power button my system is shutdown.
Anybody know how fix it?

Offline

#2 2012-10-17 18:32:06

teateawhy
Member
From: GER
Registered: 2012-03-05
Posts: 1,138
Website

Re: Hibernate when i press power button

Do you have systemd ?

Last edited by teateawhy (2012-10-17 18:32:38)

Offline

#3 2012-10-17 18:55:19

illusionist
Member
From: localhost
Registered: 2012-04-03
Posts: 498

Re: Hibernate when i press power button

see your

/etc/systemd/logind.conf

and

man logind.conf

for more help.


  Never argue with stupid people,They will drag you down to their level and then beat you with experience.--Mark Twain
@github

Offline

#4 2012-10-18 14:41:57

xorgx3
Member
From: Poland
Registered: 2011-11-29
Posts: 197

Re: Hibernate when i press power button

yes, i am using systemd.

here is my logind.conf:

[Login]
#NAutoVTs=6
#ReserveVT=6
#KillUserProcesses=no
#KillOnlyUsers=
#KillExcludeUsers=root
#Controllers=
#ResetControllers=cpu
#InhibitDelayMaxSec=5
HandlePowerKey=suspend
#HandleSuspendKey=suspend
#HandleHibernateKey=hibernate
#HandleLidSwitch=suspend
#PowerKeyIgnoreInhibited=no
#SuspendKeyIgnoreInhibited=no
#HibernateKeyIgnoreInhibited=no
#LidSwitchIgnoreInhibited=yes

And still suspend not working if i press power button.

Offline

#5 2012-10-20 13:32:16

illusionist
Member
From: localhost
Registered: 2012-04-03
Posts: 498

Re: Hibernate when i press power button

xorgx3 wrote:

...
HandlePowerKey=suspend
....

did you really see the man page ?


  Never argue with stupid people,They will drag you down to their level and then beat you with experience.--Mark Twain
@github

Offline

#6 2012-10-20 14:16:03

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,414

Re: Hibernate when i press power button

I don't think you really did your own research here.  illusionist is right in that if you read the man page, you would have solved this yourself.

From the logind.conf man page

HandlePowerKey=, HandleSuspendKey=, HandleHibernateKey=, HandleLidSwitch=
           Controls whether logind shall handle the system power and sleep keys and the lid
           switch to trigger actions such as system power-off or suspend. Can be one of
           ignore, poweroff, reboot, halt, kexec and hibernate.
If ignore logind will never
           handle these keys. Otherwise the specified action will be taken in the
           respective event. Only input devices with the power-switch udev tag will be
           watched for key/lid switch events.  HandlePowerKey= defaults to poweroff.
           HandleSuspendKey= and HandleLidSwitch= default to suspend.  HandleHibernateKey=
           defaults to hibernate.

If you don't know the possible settings, it seems a little rediculous to simply guess, then cry that it does not work as you had hoped.


Edit: added bold for emphasis... is it working?

Last edited by WonderWoofy (2012-10-20 14:18:17)

Offline

#7 2012-10-20 18:08:50

xorgx3
Member
From: Poland
Registered: 2011-11-29
Posts: 197

Re: Hibernate when i press power button

Ok, hibernate works.

BUT i don't understand one thing. What I should do if i will want suspend my computer if I press power button? And why default options of HandleLidSwitch = suspend?

Offline

#8 2012-10-20 21:10:30

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,414

Re: Hibernate when i press power button

I don't know why it indicates that in the logind.conf, maybe it is a mistake.  I guess you would have to use some other method like acpid for more fine grained control.  I have never tried to make my power button do anything but shut the computer down though.  Acpid should make it stooopid simple though.

Offline

#9 2012-10-20 22:49:19

cfr
Member
From: Cymru
Registered: 2011-11-27
Posts: 7,167

Re: Hibernate when i press power button

If that's right, the manual page is extremely misleading since the quote you gave clearly distinguishes suspend from hibernate and explicitly claims that these functions can handle suspend.

I've got a lot of these set to "ignore" as KDE/KDM wants to handle them. But it is at least bizarre if systemd logind supports hibernate but not suspend, isn't it? (I'm assuming suspend=sleep and hibernate=suspend-to-disk.)


CLI Paste | How To Ask Questions

Arch Linux | x86_64 | GPT | EFI boot | refind | stub loader | systemd | LVM2 on LUKS
Lenovo x270 | Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz | Intel Wireless 8265/8275 | US keyboard w/ Euro | 512G NVMe INTEL SSDPEKKF512G7L

Offline

#10 2012-10-20 23:42:35

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,414

Re: Hibernate when i press power button

The available options don't mention suspend, so I figured the powerkey does not do it.  Maybe you are right though, since it obviously is a function of the lid switch. 

I was referring to the fact that logind.conf is supposed to have the defualts listed and commented out, but it has #HandlePowerKey=suspend, which it does not, as my computer shuts down on the defaults.  I never changed any because I figure they were pretty sane.

Offline

#11 2013-01-10 19:18:31

plam
Member
From: Bulgaria
Registered: 2010-03-16
Posts: 37

Re: Hibernate when i press power button

xorgx3 wrote:

why default options of HandleLidSwitch = suspend?

Because this is the expected behavior of a laptop. You use it, and when you stop using it you close it, and it suspends. Then when you open it, it wakes up(some models don't wake up on their own, and you should press the power button). It is really convenient, when you want to save power during long periods away from a charger.

Offline

Board footer

Powered by FluxBB