9

I disabled the power button on my desktop (pressing it did nothing, no shutdown, no hibernation/sleep, because my kids like it to press)
After I upgraded my ubuntu from 18LTS to 20LTS, the disabled power button behaviour does not work anymore. When it is pressed, it hibernates the PC.

Here are my current settings gsettings list-recursively org.gnome.settings-daemon.plugins.power

org.gnome.settings-daemon.plugins.power lid-close-ac-action 'suspend'
org.gnome.settings-daemon.plugins.power time-critical 300
org.gnome.settings-daemon.plugins.power power-button-action 'nothing'
org.gnome.settings-daemon.plugins.power lid-close-suspend-with-external-monitor false
org.gnome.settings-daemon.plugins.power button-hibernate 'nothing'
org.gnome.settings-daemon.plugins.power idle-dim true
org.gnome.settings-daemon.plugins.power button-power 'nothing'
org.gnome.settings-daemon.plugins.power lid-close-battery-action 'suspend'
org.gnome.settings-daemon.plugins.power priority 0
org.gnome.settings-daemon.plugins.power idle-brightness 30
org.gnome.settings-daemon.plugins.power active true
org.gnome.settings-daemon.plugins.power critical-battery-action 'suspend'
org.gnome.settings-daemon.plugins.power button-suspend 'nothing'
org.gnome.settings-daemon.plugins.power button-sleep 'nothing'
org.gnome.settings-daemon.plugins.power percentage-critical 3
org.gnome.settings-daemon.plugins.power sleep-inactive-ac-timeout 3600
org.gnome.settings-daemon.plugins.power sleep-inactive-ac-type 'nothing'
org.gnome.settings-daemon.plugins.power ambient-enabled true
org.gnome.settings-daemon.plugins.power notify-perhaps-recall true
org.gnome.settings-daemon.plugins.power percentage-low 10
org.gnome.settings-daemon.plugins.power percentage-action 2
org.gnome.settings-daemon.plugins.power sleep-inactive-battery-type 'suspend'
org.gnome.settings-daemon.plugins.power time-low 1200
org.gnome.settings-daemon.plugins.power sleep-inactive-battery-timeout 1200
org.gnome.settings-daemon.plugins.power time-action 120
org.gnome.settings-daemon.plugins.power use-time-for-policy true

cat /etc/systemd/logind.conf

[Login]
#NAutoVTs=6
#ReserveVT=6
#KillUserProcesses=no
#KillOnlyUsers=
#KillExcludeUsers=root
#InhibitDelayMaxSec=5
HandlePowerKey=ignore
HandleSuspendKey=ignore
HandleHibernateKey=ignore
#HandleLidSwitch=suspend
#HandleLidSwitchDocked=ignore
#PowerKeyIgnoreInhibited=no
#SuspendKeyIgnoreInhibited=no
#HibernateKeyIgnoreInhibited=no
#LidSwitchIgnoreInhibited=yes
#HoldoffTimeoutSec=30s
#IdleAction=ignore
#IdleActionSec=30min
#RuntimeDirectorySize=10%
#RemoveIPC=yes
#InhibitorsMax=8192
#SessionsMax=8192
#UserTasksMax=33%

Have you any ideas what could be wrong?
Thank you for your help.

Matej Polák
  • 273
  • 1
  • 3
  • 9
  • 1
    are you for sure looking in the correct environment for which you are using? ie) com.canonical.unity.settings-daemon.plugins.power button-suspend OR org.mate.power-manager button-suspend ???? Are there any other desktops installed, if so, does the button work as expected there? – WU-TANG Oct 03 '20 at 00:09
  • 1
    This might help: https://unix.stackexchange.com/questions/547582/how-to-disable-cleanly-the-power-button Another option is to raise your voice when your kids do something wrong. – WinEunuuchs2Unix Oct 04 '20 at 00:39
  • is this helpfull? https://askubuntu.com/questions/1070915/prevent-power-button-to-suspend-the-pc-on-18-04 – nobody Oct 05 '20 at 10:19
  • Did you have a chance of testing the solutions posted? – sancho.s ReinstateMonicaCellio Oct 05 '20 at 10:47
  • disconnect the power button from the motherboard and configure the BIOS to power on automatically when power is restored. It would require cycling the surge protector to turn in on after shutting down. – rtaft Oct 05 '20 at 16:00
  • @WU-TANG You were right. The com.canonical.unity.settings-daemon.plugins.power was set to hibernate, so after setting it to nothing. It works now. Thank you very much. You can submit it as an answer and i will give you the bounty. – Matej Polák Oct 07 '20 at 21:28
  • you're welcome... tell the babies to have fun – WU-TANG Oct 07 '20 at 22:21

4 Answers4

5

I am not sure what is wrong with your files.

  1. The logind-way

    Did you try

    sudo systemctl restart systemd-logind
    

    or (better) rebooting?

  2. The acpid-way

    Besides, this a possible method to obtain the behaviour you are looking for. Create an ACPI handler with a file in /etc/acpi/events/

    sudo nano /etc/acpi/events/powerbtn-acpi-support
    

    (Note: as per official info, "Rules are defined by simple configuration files. acpid will look in a configuration directory (/etc/acpi/events by default), and parse all regular files that do not begin with a period ('.') or end with a tilde (~).")

    Make that file contain

    event=button[ /]power
    action=
    

    Then restart the acpi daemon with

    sudo service acpid restart
    

Notes:

  1. The cardboard-way is funny.

Sources:

https://superuser.com/questions/1523918/run-script-when-power-button-pressed

https://wiki.archlinux.org/index.php/acpid

How to prevent the Power button to shutdown directly the system?

https://superuser.com/questions/699905/change-behavior-of-linux-power-button/699925

  • I saw the /etc/acpi/events/powerbtn-acpi-support reference from 2014 in a google search. That was renamed to: /etc/acpi/events/powerbtn in my Ubuntu 16.04. Did you check if it exists on your system? – WinEunuuchs2Unix Oct 04 '20 at 00:41
  • @WinEunuuchs2Unix - Confirmed. The name of the handler can be almost anything, see updated answer for the detail. – sancho.s ReinstateMonicaCellio Oct 04 '20 at 22:17
  • What happens if system is crashed or partially crashed? Can I use long power press to shutdown computer? Is it the behaviour for short power press, right? – laimison Oct 19 '22 at 00:04
3

Ubuntu 20.04 LTS has it in the GUI controls. There is an option to make the power button "Do nothing" in the Power Button Behavior dropdown menu.
*
enter image description here

Olimjon
  • 7,292
2

Check to see if there are other desktop environments in play like:
com.canonical.unity.settings-daemon.plugins.power
or
org.mate.power-manager

You may have made the correct change, but for the wrong environment...

a more generic search of your gsettings can also help:
gsettings list-recursively | grep button on my system additionally yields:
.
.
.
com.canonical.unity.settings-daemon.plugins.power power-button-action 'suspend'
com.canonical.unity.settings-daemon.plugins.power button-hibernate 'hibernate'
com.canonical.unity.settings-daemon.plugins.power button-power 'suspend'
com.canonical.unity.settings-daemon.plugins.power button-suspend 'suspend'
com.canonical.unity.settings-daemon.plugins.power button-sleep 'hibernate'

WU-TANG
  • 3,071
0

For some reason, the sleep.conf is rarely if ever mentioned, I couldn't get anything else to work from the proposed solutions on Ubuntu Jammy (22.04LTS) so finally this one solved it:

$ sudo nano /etc/systemd/sleep.conf

Then, change the following lines like this to disable all power options:

AllowSuspend=no
AllowHibernation=no
AllowSuspendThenHibernate=no
AllowHybridSleep=no

After that, sudo ldconfig and/or a restart and you should be all set.