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,274
  • 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 03 '13 at 09:23

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
  • 19,615
  • 55
  • 79
  • 83
Osyx
  • 13
  • 1
  • 9
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.

  • @EliahKagan The second line indicates the name of the script, that was meant to be commented out, otherwise you would find a script calling itself infinitely, LOL XD. You can check your own /etc/acipt/powerbtn.sh – Mukesh Sai Kumar Dec 09 '17 at 07:59
  • @MukeshSaiKumar Sorry, it never occurred to me that it was a quote from the top of that named file--though now I see it clearly was! I've removed my comment, to avoid misleading any (more?) people whose systems still ship with the acpid package (most don't anymore) into wrongly modifying /etc/acpi/powerbtn.sh. Henrik Jutterström: Is this really saying, "No, pressing the power button causes /etc/acpi/powerbtn.sh to be run, and that script only sometimes executes the final line /sbin/shutdown -h now "Power button pressed", which is similar to sudo poweroff"? Should that be edited in? – Eliah Kagan Dec 09 '17 at 14:00
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
  • 67,791
  • 32
  • 179
  • 269