Wednesday 23 January 2008

Ubuntu bits : System shutdown by power button


Simple enough problem: the headless server is sitting under the desk, the electricity needs to go off now (and you forgot to plug in the ups). You press the power button, nothing happens (as is normal).

Sure, you could just hold down the power button (or pull the plug). the file system will likely survive. Or you could fire up an ssh client and do a graceful shutdown. But if only that power button worked.


Well turns out the solution (for the next time it happens) is simple:

  1. Make sure your ACPI support is all happy.

    dmesg | grep 'ACPI:'

    If it's not - then you need to enable it in the kernel.
  2. Make sure ACPI has detected your power button.

    dmesg | grep 'ACPI: Power Button'

    If you have no luck, there's a kernel module you can load easily enough. Load it up, and check that it actually got loaded.

    sudo modprobe button
    lsmod | grep button

    Assuming all is well, add it to the boot time module list in /etc/modules
  3. Use acpid to monitor ACPI events and shutdown when the power button is pressed.

    sudo apt-get install acpid

    That's it. The default acpid scripts will intercept the power button and force an immediate halt.
  4. Optional : If you are really keen. Reboot, then:

    tail -f /var/log/syslog

    Then press the power button and enjoy the graceful shutdown.
  5. Bonus Points: If you don't the default event handler, tweak /etc/acpi/powerbtn.sh till your content.

No comments: