29

I am using GNOME 3.18.1 on Arch Linux 4.2.5-1-ARCH x86_64 on a Dell E6530 laptop. Since I installed this OS years ago, the power button on my laptop has always led my OS to completely power down.

However, in the last few weeks this behaviour has changed, so that pressing the power button now puts my laptop into energy savings mode. I did not change my power settings. I always keep my system up to date using pacman -Syyu, however, so I suspect that an update changed this functionality.

In the power settings there is no option for this.

How can I restore the initial behaviour, so that pressing that button powers the system off?

3
  • 2
    @Konrad As a second step, you may want to verify that indeed Gnome is the culprit. That is an assumption. If you try changing shells, you might learn something. Can you also list what steps you did take to debug this issue. Nov 10, 2015 at 16:22
  • 1
    What changed? Did you upgrade something? What operating system (including versions) are you running? On what hardware? What were you running when it worked? Nov 10, 2015 at 23:54
  • Sorry for the missing information, I updated my post. Nov 11, 2015 at 16:43

9 Answers 9

23

That's caused by the latest gnome-settings-daemon updates...
There is no such option in power settings because it was removed by the GNOME devs (the shutdown/power off action is considered "too destructive").
Bottom line: you can no longer power off your laptop by pressing the power off button.


You could however add a new dconf/gsettings option (i.e.shutdown) to the settings daemon power plugin if you're willing to patch and rebuild gnome-settings-daemon:

--- gnome-settings-daemon-3.18.2/data/gsd-enums.h   2015-11-10 09:07:12.000000000 -0500
+++ gnome-settings-daemon-3.18.2/data/gsd-enums.h   2015-11-11 18:43:43.240794875 -0500
@@ -114,7 +114,8 @@
 {
   GSD_POWER_BUTTON_ACTION_NOTHING,
   GSD_POWER_BUTTON_ACTION_SUSPEND,
-  GSD_POWER_BUTTON_ACTION_HIBERNATE
+  GSD_POWER_BUTTON_ACTION_HIBERNATE,
+  GSD_POWER_BUTTON_ACTION_SHUTDOWN
 } GsdPowerButtonActionType;

 typedef enum
--- gnome-settings-daemon-3.18.2/plugins/media-keys/gsd-media-keys-manager.c    2015-11-10 09:07:12.000000000 -0500
+++ gnome-settings-daemon-3.18.2/plugins/media-keys/gsd-media-keys-manager.c    2015-11-11 18:47:52.388602012 -0500
@@ -1849,6 +1849,9 @@

         action_type = g_settings_get_enum (manager->priv->power_settings, "power-button-action");
         switch (action_type) {
+        case GSD_POWER_BUTTON_ACTION_SHUTDOWN:
+                do_config_power_action (manager, GSD_POWER_ACTION_SHUTDOWN, in_lock_screen);
+                break;
         case GSD_POWER_BUTTON_ACTION_SUSPEND:
                 do_config_power_action (manager, GSD_POWER_ACTION_SUSPEND, in_lock_screen);
                 break;

Once you install the patched version, a new shutdown option will be available in dconf-editor under org > gnome > settings-daemon > plugins > power > power-button-action:

enter image description here

so select that to shutdown via power button or, if you prefer CLI, run in terminal:

gsettings set org.gnome.settings-daemon.plugins.power power-button-action shutdown

Sure, for the above to work you also need the right settings in /etc/systemd/logind.conf:

HandlePowerKey=poweroff
PowerKeyIgnoreInhibited=yes

Keep in mind that pressing the power button will shutdown your system without any warning.

5
  • 12
    That is very disappointing, I always thought Linux is the OS where the user decides what he wants even if it is dangerous. But thank you very much for finding this out, at least I don't waste my time in the search of a nonexisting fix then. Nov 12, 2015 at 18:13
  • Thank you very much for the detailed solution. Despite having gnome-settings-daemon 3.18.2-1, my installation has different files, however: gsd-enums.h is in the folder /usr/include/gnome-settings-daemon-3.0/gnome-settings-daemon/ and gsd-media-keys-manager.c does not exist at all. Dec 3, 2015 at 9:51
  • Dev has reversed his decision and restored the interactive option in gnome-settings-daemon 3.20. (I think. I haven't updated to that version yet.)
    – idbrii
    Sep 20, 2016 at 16:07
  • 2
    @idbrii - well, I have some bad news for you: I'm on 3.22 and there's no shutdown option. Sep 20, 2016 at 16:34
  • @don_crissti The "interactive" option presents the user with a dialog asking for an action (Restart, Power Off, or Cancel). If there's no input in 60 seconds, it powers off. Not as good as a direct shutdown action, but at least you can power off your system with the power button again. Source: access.redhat.com/documentation/en-us/red_hat_enterprise_linux/…
    – Jonathan
    Aug 21 at 13:12
17

In Ubuntu 18.04 or any similar Linux variants with acpi (if not you can probably install), make a file called /etc/acpi/events/power with

sudo nano /etc/acpi/events/power

and put

event=button/power
action=/sbin/poweroff

inside the file, close it, then

sudo service acpid restart

This is probably the simplest solution that definitely works.

3
  • 3
    This solutions works great in my situation : ubuntu server 18.04 with gnome-desktop installed and in headless mode (not necessary when a display is connected). Thanks !
    – M-Jack
    Jan 25, 2019 at 9:36
  • After trying so many "solutions" that either didn't work or only worked once, this finally is an actual solution! Why would the way of solving something like this even involve fiddling with gimmicky desktop environment settings?
    – UTF-8
    Nov 23, 2020 at 13:29
  • Thank you so much! Rewrote it as an automated copy pasta fix: sudo cat > /etc/acpi/events/power << 'EOF' event=button/power action=/sbin/poweroff EOF sudo service acpid restart Mar 27 at 12:14
12

As @don_crissti explained, the situation is silly because it really isn't possible to just shutdown without confirmation using the normal settings.

However, there's a workaround: if the chassis type of the machine is set to "vm" (virtual machine), the old immediate shutdown behavior will take over any settings. Simply enter as root:

hostnamectl set-chassis vm

and reboot once. I don't know of any side effects of this settings.

8
  • 2
    I've followed this power-button issue for a long time link Our application has a keyboardless / mouseless configuration "view only" mode that needs to be turned off by non-technical staff every night. When the ability to shut down with power button was lost, they would need to just pull the plug. This solution works great for us and is by far the easiest approach for us.
    – MikeV
    Apr 16, 2018 at 22:44
  • This didn't work for me, I am not sure why. The /etc/acpi/events/power solution did though, perfectly.
    – tbeauvais
    Jun 5, 2020 at 9:57
  • Great workaround, thx! Tested with 20.04. Note I needed this when no one is logged in. When someone is logged in the other, gsettings solution is enough.
    – MarcH
    Jun 20, 2020 at 18:23
  • 1
    Side effect: airplane mode will not work (it'll be ignored). I tried to create a pull request to allow an embedded chassis type to power off immediately (like vm), but it was not accepted. Oct 20, 2020 at 16:04
  • On 20.04 for me it seems to have disabled X server for some reason. Had to "nvidia-xconfig --enable-all-gpus" to remake xorg.conf
    – Íhor Mé
    Jan 4, 2021 at 21:26
3

As an alternative, you can open up the keyboard settings window and assign a custom keyboard shortcut to the command gnome-session-quit --power-off, which will bring up the shutdown menu. I have it set to trigger by Super+q.

2

As a first step, you should make sure that Settings | Power (assuming Gnome v3) "Suspend & Power Off" / "Automatic Suspend" is set to off. Basically, disable GNOME power setting features and just let the system take over.

0

The custom keyboard shortcut works, I set it to gnome-session-quit --power-off --force by pressing only the power button, which is all that I wanted.

2
  • 1
    Really? For me this does not work. The button still behaves according to power-button-action option. I can set Ctrl+PowerOff as the shortcut key however.
    – Alexey
    Aug 25, 2016 at 23:55
  • Same problem for me. @Alexey Sep 19, 2016 at 9:32
0

I found another option to accomplish this on Debian Stretch. I installed the package acpi-support-base and edited the file /etc/acpi/powerbtn-acpi-support.sh adding the following lines following the header comment and before any code.

## Bypass logic to force shutdown on power button
/sbin/shutdown -h -P now "Power button pressed"
exit 0

This is a bit of a blunt instrument but works for me on a desktop and should work on a laptop. It also bypasses the Gnome3 settings but is easier than patching Gnome and recompiling.

According to the Arch Wiki page on acpid this can probably be implemented by modifying /etc/acpi/handler.sh on Arch.

0

I worked around this problem on a server of mine by monitoring the log output of systemd-logind basically refining the solutions presented in other answers.

This workaround requires two files. The script that triggers the actual shutdown event

$ cat /usr/local/bin/shutdown_button_monitor.sh
#!/bin/sh

# ansible managed

# systemd-logind prints a line of the form 
# Dez 21 11:12:10 box03.yeepa.de systemd-logind[748]: Power key pressed.
# on key press, but doesn't handle the button because gnome3 blocks systemd from doing so.
# See `systemd-inhibit` for that.

# first sleep a minute so we have chance to disable this scritp if it runs amok
sleep 1m

# so we workaround gnome a bit here.
journalctl -u systemd-logind --follow --lines=0 | \
while read line ; do
    if echo "$line" | grep --quiet 'Power key pressed'
    then
        systemctl poweroff
    fi
done

and the service file that starts / restarts it

$ cat /etc/systemd/system/shutdown_button_monitor.service
# ansible managed

[Unit]
Description=Power off the machine if the power button is pressed
# Workaround for gnomes block of the shutdown button
# https://unix.stackexchange.com/questions/242129/gnome-3-how-to-set-power-button-to-shutdown-instead-of-suspend#242452
# Monitor these blocks yourself with `systemd-inhibit`

[Service]
User=root
ExecStart=/usr/local/bin/shutdown_button_monitor.sh
Restart=always
RestartSec=5

[Install]
WantedBy=multi-user.target
-1

Some while ago I created this handy script: https://github.com/stackcoder/doublepress

It can prevent accidental shutdowns by requiring double pressing the power button. It also allows switching between standby and poweroff, or triggers your custom action.

2
  • This does not actually address the issue in the question at all.
    – Kusalananda
    Jan 21, 2021 at 8:27
  • Indeed, the core question is "How can I restore the initial behaviour, so that pressing that button powers the system off?", and an answer has been accepted, so for the future, keep in mind that Answers should address the Question. This Answer could be salvaged by integrating that script to the OP's environment.
    – Jeff Schaller
    Jan 21, 2021 at 17:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .