How can I set the power button (on my computer case, not keyboard) to power off the system with systemd
(without acpid
)?
3 Answers
systemd
can handle this. I think this is what you need:
Open the /etc/systemd/logind.conf
(manual):
HandlePowerKey
: action on power key is pressed;HandleSuspendKey
: action on suspend key is pressed.HandleHibernateKey
: action on hibernate key is pressed.HandleLidSwitch
: action when the lid is closed.
The action can be one of ignore
, poweroff
, reboot
, halt
, suspend
, hibernate
or kexec
.
If no configuration, default values used:
HandlePowerKey=poweroff
HandleSuspendKey=suspend
HandleHibernateKey=hibernate
HandleLidSwitch=suspend
-
I think this parameters related with buttons on keyboard ("Power", "Sleep", etc.), isn't it? (Unfortunately, I can't check it now.)– user14284Oct 13, 2012 at 10:16
-
I'm frustrated. =) What's the difference? The power button is the button, by which you power on the PC. Anyway, long press of this key would halt PC regardless of OS settings.– m0nhawkOct 13, 2012 at 10:22
-
I set all
Handle*Key
to ignore, because button 'Power', 'Sleep' and 'Wake' are placed near arrows and Enter on my keyboard. I can press it by accident. I need to handle power button on my computer case.– user14284Oct 13, 2012 at 10:27 -
Can you provide more info about keys? For example model of keyboard or PC, because I stop understanding of what keys you are talking.– m0nhawkOct 13, 2012 at 10:34
-
I don't see it's related with systemd, but on my system that has acpid
installed, it respond to power button press automatically.
Can be defined through /etc/acpi/handler.sh
(On Arch Linux)
-
It's related with
systemd
becausesystemd
replaceacpid
's functionality. I can use bothsystemd
andacpid
anyway, but I want to use only the first one. I have edited my question.– user14284Oct 13, 2012 at 9:17
I believe you need to configure that in your BIOS (if it supports it). I don't see how the power button on the case has anything to do with your OS, where a power button on your keyboard does interact with the OS since the OS loads drivers for the keyboard.
-
I have seen as pressing power button on case cause correct poweroff of MS Windows. So, generally speaking, OS can handle power button on case.– user14284Oct 13, 2012 at 10:41
-