Power button, shutdown
From Ubuntuwiki.net
If you want your Ubuntu Server to shut down when a user presses the power button, you'll need the acpid package installed:
sudo apt-get install acpid
In most cases, that should be all you need to do. If it still doesn't work, you need to make sure that ACPI is enabled in BIOS, that you aren't booting with the "noacpi" flag, and finally you can check the contents of /etc/acpi/events/powerbtn - it's a shell script; you should be able to follow what it does by reading it.