Linux выключение по кнопке

How to set power button to shutdown instead of suspend?

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?

@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.

What changed? Did you upgrade something? What operating system (including versions) are you running? On what hardware? What were you running when it worked?

9 Answers 9

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.

Читайте также:  Arch linux group users

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.

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.

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.)

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 
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.

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 !

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?

Thank you so much! Rewrote it as an automated copy pasta fix: sudo cat > /etc/acpi/events/power

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.

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.

This didn't work for me, I am not sure why. The /etc/acpi/events/power solution did though, perfectly.

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.

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.

Читайте также:  Kali linux black screen virtualbox

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

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 .

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.

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.

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.

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.

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 

Источник

ВЫКЛЮЧЕНИЕ КОМПЬЮТЕРА С ПОМОЩЬЮ КНОПКИ POWER В GNU/LINUX

Действительно, всё перечисленное ниже можно сделать с помощью acpid. И да, так было бы гораздо лучше. Но мне хотелось размять буйну голову, да соорудить миленький велосипедик. Зато свой. И еще одно уточнение – на моём системном блоке есть только кнопка Power.

Читайте также:  Обновить группы пользователя linux

Итак, написана была маленькая программка на C, которая делает только одну вещь: выполняет команду при нажатии кнопки Power на системном блоке.

В Unix всё – файл, а поэтому можно читать сообщения с “файлов” устройств. Что и было использовано. Необходимо только определить: какой файл в папке /dev относится к кнопке выключения. Можно даже сузить поиски: какой файл из event в папке /dev/input. Я лично просто перебрал всё что было в этой директории по очереди командой:
$ cat /dev/input/event0

Компилируется она просто (если эти строки скопировать в файл с именем button.c):
$ gcc button.c -o powerbuttond

Затем необходимо переместить программку в какую-нибудь root’овскую папку с бинарниками:
# mv powerbuttond /usr/sbin/

Окончательно протестировать работу можно вот так:
# powerbuttond /dev/input/event1 "ls -a -l"

Если всё работает, то осталось только написать скрипт для systemd или SysVinit (мой случай):
case $ in start) powerbuttond /dev/input/event1 "/sbin/halt" & ;; stop) killall powerbuttond ;; *) echo "Usage: $ " exit 1 ;; esac exit 0

Заменив /sbin/halt на команду отключения, которая вам по душе.

Источник

Выключение компьютера с помощью кнопки Power в GNU/Linux

Действительно, всё перечисленное ниже можно сделать с помощью acpid. И да, так было бы гораздо лучше. Но мне хотелось размять буйну голову, да соорудить миленький велосипедик. Зато свой. И еще одно уточнение – на моём системном блоке есть только кнопка Power.

Итак, написана была маленькая программка на C, которая делает только одну вещь: выполняет команду при нажатии кнопки Power на системном блоке.

В Unix всё – файл, а поэтому можно читать сообщения с “файлов” устройств. Что и было использовано. Необходимо только определить: какой файл в папке /dev относится к кнопке выключения. Можно даже сузить поиски: какой файл из event в папке /dev/input. Я лично просто перебрал всё что было в этой директории по очереди командой:
$ cat /dev/input/event0

Компилируется она просто (если эти строки скопировать в файл с именем button.c):
$ gcc button.c -o powerbuttond

Затем необходимо переместить программку в какую-нибудь root’овскую папку с бинарниками:
# mv powerbuttond /usr/sbin/

Окончательно протестировать работу можно вот так:
# powerbuttond /dev/input/event1 "ls -a -l"

Если всё работает, то осталось только написать скрипт для systemd или SysVinit (мой случай):
case $ in start) powerbuttond /dev/input/event1 "/sbin/halt" & ;; stop) killall powerbuttond ;; *) echo "Usage: $ " exit 1 ;; esac exit 0

Заменив /sbin/halt на команду отключения, которая вам по душе.

Источник

Оцените статью
Adblock
detector