LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu
User Name
Password
Ubuntu This forum is for the discussion of Ubuntu Linux.

Notices


Reply
  Search this Thread
Old 08-09-2018, 08:44 AM   #1
coldbeer
Member
 
Registered: May 2006
Location: Orion–Cygnus Arm, MWG
Distribution: Slackware, Ubuntu
Posts: 249

Rep: Reputation: 130Reputation: 130
Trying to make Ubuntu 18.04 shutdown on power button.


We have Ubuntu 18.04 desktop machines used in a remote lab setting that may or may not have keyboards and monitors attached to them at any point in time. It is necessary to be able to shutdown and restart the machine with only the power button.

This means Ubuntu must shutdown via the power button consistently whether the user is logged in or the machine just sitting at the login screen.

So far I have set:

Code:
gsettings set org.gnome.settings-daemon.plugins.power button-power shutdown
gsettings set org.gnome.settings-daemon.plugins.power button-hibernate shutdown
gsettings set org.gnome.settings-daemon.plugins.power button-suspend shutdown
gsettings set org.gnome.settings-daemon.plugins.power button-sleep shutdown
and created /etc/acpi/events/power

Code:
event=button/power
action=/etc/acpi/power.sh "%e"
and create /etc/acpi/power.sh

Code:
#!/bin/sh
/sbin/shutdown -h now "Power button pressed"
All of the above allows Ubuntu to shutdown gracefully when a user is logged in and the power button is pressed.

However if the machine is setting at the login screen and the power button is pressed, the machine STILL goes into some type of hibernate mode. If I then press the power button a second time, it comes out of hibernation and the power.sh runs and then it shuts down.

I have tried changing settings in /etc/systemd/logind.conf:

Code:
HandlePowerKey=poweroff
HandleSuspendKey=poweroff
HandleHibernateKey=poweroff
But that doesn't work.
 
Old 08-09-2018, 08:58 AM   #2
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
I know slackware, Manjaro, Void, and a few others I've tried as well all shut down whenever I push my power button (laptop). I have not install Ubuntututu in many years, refuse to.

Would not Ubuntututututu have in its settings gui where you can tell it what to do whenever you push the power button, close the lid, leave the screen inactive for X amount of time etc? Power Management? being a windows wantabe, I'd think it would. unless you do a hard shut down, which is not always a good thing. but if no monitors then how do you even know if it did work or not?
 
Old 08-09-2018, 11:48 AM   #3
coldbeer
Member
 
Registered: May 2006
Location: Orion–Cygnus Arm, MWG
Distribution: Slackware, Ubuntu
Posts: 249

Original Poster
Rep: Reputation: 130Reputation: 130
My best guess after searching for hours is that this "clever" gnome programmer's work is still in effect:

Code:
        case GSD_POWER_BUTTON_ACTION_NOTHING:
                /* do nothing */
                break;
        }
As he says "In later commits, we'll hard-code the actions for tablets and virtual machines. Note that "power off" is not an option as this would make the default action too destructive."

and
Code:
<description>The action to take when the system power button is pressed. This action is hard-coded (and the setting ignored) on virtual machines (power off) and tablets (suspend).</description>

Because HACK fixes the situation but leaves unknown ramifications in question:

# hostnamectl set-chassis vm

If this is still the case, I'm very disappointed in gnome's volunteer vetting. Hard coding? Really?

Last edited by coldbeer; 08-14-2018 at 06:35 AM.
 
Old 08-09-2018, 04:01 PM   #4
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
I'm not sure how to do this, i'd have to dig into it, but I do remember seeing in some system I was running that the power button pressed just called "shutdown -now" which is the proper CLI shutdown command. so if you could figure out how to gain access to know when the power button is pressed then you could try to attach a script, or other means to call the shutdown -now command.
 
Old 08-14-2018, 06:35 AM   #5
coldbeer
Member
 
Registered: May 2006
Location: Orion–Cygnus Arm, MWG
Distribution: Slackware, Ubuntu
Posts: 249

Original Poster
Rep: Reputation: 130Reputation: 130
I set all the configs back to defaults and deleted the acpi scripts that I tried. So the machine was back to its original installed configuration.

Solution

Then I changed the chassis type

Code:
# hostnamectl set-chassis vm
Then I set the set the gsettings button-power

Code:
# gsettings set org.gnome.settings-daemon.plugins.power button-power shutdown
Then rebooted.

This is the workaround I found here:

https://unix.stackexchange.com/quest...suspend#416569

Now Ubuntu 18.04 will gracefully shutdown when the power button is pressed whether or not the user is logged in.

Last edited by coldbeer; 08-14-2018 at 06:36 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Configure power button to shutdown PC hifi100 Debian 1 09-01-2017 05:46 PM
[SOLVED] Ubuntu Gnome applet panel power button won't shutdown machine EDDY1 Linux - Newbie 3 11-05-2010 03:52 AM
Power Button for Shutdown gokul Linux - Hardware 4 01-24-2004 12:40 PM
Shutdown with power button hriosm Linux - Hardware 4 06-06-2003 02:43 PM
Shutdown routine with power button bfought Linux - Newbie 2 09-09-2002 06:23 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu

All times are GMT -5. The time now is 05:41 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration