My solution involves the following steps:
gsettings to stop sending the power-off events to Gnome
- Create a custom event handler as outlined in the
To turn off event handling by Gnome:
gsettings set org.gnome.settings-daemon.plugins.power button-power nothing
gsettings set org.gnome.settings-daemon.plugins.power power-button-action nothing
Now to create the custom event handler for the power button (do the following as root):
/etc/acpi/events create the event file. I called mine
button-power with the following contents:
The bit in braces is
regexp for "space, slash or dash". If you're confident your kernel supplies only slashes you can go with the explicit character.
etc/acpi create the script file you referred to above (
powerbtn.sh) with the following contents:
/usr/bin/logger "Custom shutdown in response to event $1"
/sbin/shutdown -h now "Custom shutdown: $1"
Either reboot or send your
SIGHUP and your power button will now instantly initiate a controlled shutdown.