Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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).

share|improve this question
    
Have you tried following the steps here to modify the power button behaviour using dconf? –  jpd Jul 30 '12 at 20:34
1  
You can press as well as long-press the power-button, which one are you talking about? (Press will shut down if you have asked it to, in the settings shown by jpd, long-press probably won't- it just disconnects the power to the machine) –  Jobin Jul 3 '13 at 9:23
add comment

3 Answers

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.

share|improve this answer
add comment

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.

share|improve this answer
1  
That script does nothing, as it consists entirely of comments. Did you comment out the second line (by removing the # from the beginning)? Anyway, if this worked for you, please mark it as the accepted answer by clicking the gray check mark to the left of it. (You can do this since it's been 2 days since you posted it.) –  Eliah Kagan Jan 20 '13 at 11:41
add comment

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
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.