1

I have a headless Ubuntu server running 64 bit Ubuntu 12.04 server edition, and I connect to the server via SSH from my Windows laptop.

Sometimes when I would like to turn off the server and my laptop is powerd off, I then need to boot up my laptop in order to log on to the server and type sudo poweroff for it to power off properly.

My question is, if I press the physical power on/off button on the server, will it have the same affect as sudo poweroff? I mean, will this trigger a sudo poweroff command or is this an improper way to do it if my laptop isn't started?

(and no, I'm not describing holding the button in as long as if the server is not responding)

A similar function is implemented in Windows where I can choose what the power button should do (sleep/log off/power off).

kingmilo
  • 10,784

3 Answers3

1

From what I know: Yes, it's a safe way to do it, it's exactly the same as saying sudo shutdown now -h -H.

It's the same on Windows and any other OS. If you long press the shutdown button, that's an unsafe way of doing it.

Kevin Bowen
  • 20,055
  • 57
  • 82
  • 84
Osyx
  • 13
0

I found the answer my self here: https://wiki.ubuntu.com/PowerManagement#Handling_hardware_events

#!/bin/sh
# /etc/acpi/powerbtn.sh
# Initiates a shutdown when the power putton has been
# pressed.

And as you can see the script tells me that Ubuntu will initialize a poweroff function when the button is pressed. Then I also asume that this is a safe way to do it. If not, please let me know by commenting.

0

You can edit /etc/acpi/powerbtn.sh to just run shutdown -h now as the first thing so it looks like:

#!/bin/sh
# /etc/acpi/powerbtn.sh
# Initiates a shutdown when the power putton has been
# pressed.

/sbin/shutdown -h now "Power button pressed"
exit 0
Braiam
  • 69,112