Thursday, January 19, 2012

Linux: power off confirmation

There are situations when you need to configure your Linux machine to be powered off when somebody shortly press the power button. This is usually the case when you will install acpid (Advanced Configuration and Power Interface event daemon).

But what if you need some sort of confirmation that your command have been received and the system is in the shutdown cycle?

Well, all you have to do is to tweak the action parameter from /etc/acpi/events/power.conf and my suggestion could be found bellow.

Let's take a Centos or any RHEL based distribution and test it!

yum install acpid

in /etc/acpi/events/power.conf:

  • comment the default action (inserting # as the first character of the line)
  • add the following line at the end of the file
action=/bin/ps awwux | /bin/grep gnome-power-manager | /bin/grep -qv grep || (/bin/echo -e \\a >> /dev/console;/bin/sleep 0.25;/bin/echo -e \\aPower button event ! >> /dev/console;/bin/sleep 0.25;/bin/echo -e \\a >> /dev/console;/sbin/shutdown -h now)

All we have now is to restart the acpid service:

service acpid restart

In this way, when the case power button will be pressed shortly, 3 short beeps will be heard (in case your machine have an internal speaker) before the final shutdown command is triggered.

1 comment:

Ioan (Nini) Indreias said...

For OpenSuse (11.4) there are some changes to be used:

1. instead of /etc/acpi/events/power.conf please edit /etc/acpi/events/power_button

2. the new action should be:
action=/bin/echo -e \\a >> /dev/console; /bin/sleep 0.25; /bin/echo -e \\aPower button event ! >> /dev/console; /bin/sleep 0.25; /bin/echo -e \\a >> /dev/console; /usr/lib/acpid/power_button