Change Behavior of Linux Power Button

29

9

I have a headless linux mint machine that I use for a file server and other things. It's been working great for me for a few years, but there's one issue - my cat likes to hang out on top of it, and when she climbs off and on she occasionally steps on the power button and shuts off the machine.

Is there an easy way to change the behavior of the power button so it requires an extremely long duration press (10 seconds or so) or multiple presses in order to do anything?

schizodactyl

Posted 2014-01-10T17:42:53.933

Reputation: 393

Heh. Not only do I have the the same problem, it's for exactly the same reason. To @terdon's question, it's a desktop, but the power button is on the top of the front panel facing up. It's in just the right place for a cat to put a paw on when jumping off the top of the case. – Sam Hanes – 2016-03-28T20:42:56.297

2If you have a reset button, it's often smaller and harder to press. If so, you can wire it up as the power button, and disconnect the actual power button. That's how I deal with my cat related power button issues :) – Roger Dahl – 2016-06-09T03:14:08.093

1Same problem, but with my kids accidently pressing the power button… :-) – Júda Ronén – 2017-09-29T07:53:14.813

Same problem, but caused by me spilling water on my laptop, causing some electrical shortcut triggering the power-off button randomly. – berkes – 2019-05-06T12:55:46.863

Is this a desktop or a laptop? I'm guessing laptop if that cat has access to the power button. – terdon – 2014-01-10T17:45:43.017

3It's a desktop - is this actually relevant to a software solution? – schizodactyl – 2014-01-10T22:16:45.107

Answers

17

Well, one thing you could do is simply disable the power button altogether. Personally, I only use it to turn on my machine, and never use it once the machine is on. If this is an OK solution for you, edit /etc/acpi/events/powerbtn-acpi-support:

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

That file should look something like this:

event=button[ /]power
action=/etc/acpi/powerbtn-acpi-support.sh

To make the power button do nothing, change it to:

event=button[ /]power
action=

Then restart the acpi daemon with

sudo service acpid restart

Your power button should no be ignored.

terdon

Posted 2014-01-10T17:42:53.933

Reputation: 45 216

2Thank you very much! My kitten used to power off my computer! :) – Geradlus_RU – 2014-12-22T10:22:48.220

I'm not really comfortable disabling the button entirely as, since it's a headless machine, if sshd were to crash or something along those lines my only recourse would be to cut off power to the machine. I'd much rather still leave myself with the ability to shut down gracefully if possible. – schizodactyl – 2014-01-10T22:20:42.263

1

@schizodactyl on my laptop, the solution above disables only the single press of the power button. A long press will still shut the machine down (though not very gracefully). I don't have access to a desktop at the moment so I can't test how it would work but, presumably, it will do the same. You can also map a shortcut to the shutdown command if you have a keyboard attached.

– terdon – 2014-01-11T02:28:13.220

37

terdon's answer is correct in most cases, but for distributions that have adopted systemd-logind it handles power events instead of acpid. On those distributions, add or edit this setting /etc/systemd/logind.conf to disable the power button:

HandlePowerKey=ignore

To pick up the new setting, restart logind with

sudo systemctl restart systemd-logind

On some older distributions logind can't be restarted while a desktop session is active, in which case you'll need to reboot in order to pick up the new setting.

Sam Hanes

Posted 2014-01-10T17:42:53.933

Reputation: 471

3It looks like it's the working solution for ubuntu 14.04 when you're not using gnome (i3wm in my case). – Grzegorz – 2017-09-19T04:55:52.470

I also had to set PowerKeyIgnoreInhibited=yes or switch off the power-handling of my DE (gnome-settings). Both solutions helped to make Gnome ignore the power-button too. – berkes – 2019-05-06T12:58:31.970

This worked a treat for my MacBook Air running Debian Stretch. The power button is just way too close to backspace. – Chad Schouggins – 2019-08-24T00:36:04.083

It's actually both. The ACPI system still works, but cedes control to logind if it's detected. That actually makes this solution better because if logind is failing, you probably want the power button to do a proper shutdown by default. – Walf – 2019-10-11T01:10:10.007

12

Duct-tape a cardboard guard over the button. Take three pieces of corrugated cardboard, and cut a hole in each large enough for your finger to reach through to the button. Glue them together, with the hole aligned, then duct tape the assembly around the button. All hail our feline overlords!

K7AAY

Posted 2014-01-10T17:42:53.933

Reputation: 6 962

1https://web.archive.org/web/20160429084659/http://www.retrologic.com/jargon/M/molly-guard.html is the new link to Molly-guard as the original link failed. – K7AAY – 2019-06-05T21:09:38.527

3

See: Molly-guard

– jwygralak67 – 2014-01-10T22:00:02.550

3As this is legitimately what I was considering doing if there's no good software solution, I can't really fault you for suggesting it... – schizodactyl – 2014-01-10T22:18:16.237

1

First you could edit your keymap file to change the behavior of the power button to assign it to an other key

Edit the file : /usr/share/X11/xkb/symbols/inet (edit POWR key)

Then you will need to disable the power button efficiently a good method is with xinput

run xinput --list power buttons have their own entry... pick the device number then run

xinput disable devnumber something like xinput disable 8

intika

Posted 2014-01-10T17:42:53.933

Reputation: 839