Xfce Forum

Sub domains
 

You are not logged in.

#1 2020-01-07 05:36:01

njares
Member
Registered: 2020-01-07
Posts: 4

Laptop won't shutdown when the lid is closed

Hello,

As written on the subject, I can't get my laptop to shutdown when the lid is closed. I have a script that I want to run when I'm done working and want to shutdown my laptop. But if the script takes too long and I decide to close the lid of my laptop before it ends, the laptop won't shutdown. Instead, it appears to reach an almost-halt runlevel... Where it stays indefinitely, until I open the lid again. In that precise moment, I see the screen briefly turning on, just to completely halt the next moment.

I would like my laptop to actually halt after my script has ended. So far I've tried with "xfce4-session-logout --halt" and "shutdown -h now", and both behaves the same. If I keep the lid open until the script ends, the laptop halts normally. If I close the lid before it ends, the script ends normally, the shutdown starts, but get stuck on that almost-halt runlevel.

I've been searching on google and all I can found was this thread https://forum.xfce.org/viewtopic.php?id=9653. I've found another threads on other forums, but very old ones, and with different GNU/Linux distributions.

xfce version: 4.12
Distribution: Debian stable

I'm not even sure if this is a issue with xfce or debian, or both... but since the most similar issue I found was in this forum, I decided to start here. If this post is best suited for another forum, I would appreciate if someone can point me in the right direction (this is the very first forum post I've made in my entire life). Also I can provide more information if needed.

Best regards

PS: Sorry for my bad english

Offline

#2 2020-01-07 16:15:34

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 10,948

Re: Laptop won't shutdown when the lid is closed

Hello and welcome. Have you tried systemd-inhibit?


Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#3 2020-01-07 22:30:04

njares
Member
Registered: 2020-01-07
Posts: 4

Re: Laptop won't shutdown when the lid is closed

Hello Toz,

No, I haven't tried that. And after a quick read to the link provided I'm not sure if that would help. I mean, the script does work fine with the lid closed or open. I know that because the scripts logs its activity on a file with timestamps, so I know for sure that it works as intended. I'm on my way out now, I'll read it more carefuly and try to use systemd-inhibit later today. Thank you very much in advance!

Offline

#4 2020-01-08 22:06:35

njares
Member
Registered: 2020-01-07
Posts: 4

Re: Laptop won't shutdown when the lid is closed

Hello,

I've tried systemd-inhibit and my laptop still won't shutdown. Here's what I've tried:

In python:

import subprocess
subprocess.run(['sleep','5']) # just to have time to close the lid, here's where my code would actualy execute
subprocess.run(['xfce4-session-logout','--halt'])

And then on bash:

$ systemd-inhibit --what="sleep:idle:handle-power-key:handle-suspend-key:handle-hibernate-key:handle-lid-switch" python3 test.py

I've also tried writing a bash script like:

sleep 5
xfce4-session-logout --halt

And run it with:

$ systemd-inhibit --what='sleep:idle:handle-power-key:handle-suspend-key:handle-hibernate-key:handle-lid-switch' bash test.sh

And also changing the last line with "shutdown -h now" and running with root privileges.

In all cases happens the same thing: with the lid open everything works fine, but with the lid closed it reaches that almost-halt state. If I open the lid, the screen turns on, and then the laptop shuts down inmediately.

I don't know if I'm using systemd-inhibit properly or as you tried to point out in your post.

Offline

#5 2020-01-09 00:03:36

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 10,948

Re: Laptop won't shutdown when the lid is closed

I believe that you need to run systemd-inhibit against your script. So, assuming your script is called "myscript", then the command would be:

systemd-inhibit --what="sleep:idle:handle-power-key:handle-suspend-key:handle-hibernate-key:handle-lid-switch" myscript

...and that you don't need to run xfce4-session-logout (it's actions will be inhibited by the systemd-inhibit command).

So basically, run the above to start your script. When you close the lid of the laptop, the sleep event will be delayed until the script completes.


Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#6 2020-01-09 07:16:28

njares
Member
Registered: 2020-01-07
Posts: 4

Re: Laptop won't shutdown when the lid is closed

Hello,

I'm still not sure if I understand what you mean. Just in case, let me clarify some points:

- My script does runs perfectly with the lid closed. I know that because I've done it to log its activity in a logfile with timestamps, and also it send a notification to my phone when it's done. So, even with the lid closed, I still get the notifications. But the next day when I open my laptop's lid, it is still on. So my problem is not that my script is interrupted with a sleep or something like that when the lid is closed, but that the final shutdown does not occur properly.

- I do want the laptop to shutdown after my script has finished running, that's why in my MWE there are 'xfce4-session-logout --halt' or 'shutdown -h now' calls. But when the lid is closed, it kind of start the shutdown process, but stops before halting completely. It seems to me that the shutdown process actually begins because the network an hard drive leds turn off, but the on/off light is still on. And (not always) when I open the lid the next day and the screen briefly turns on, I see a flash of the shutdown log before it completely halts. And the time it takes to finally shutdown after I open the lid seems quite less than the time it usually takes to shutdown if I don't close the lid at all.

I've been doing some more experiments. If I log into a terminal with Ctrl+Alt+F1, stop lightdm with '$ sudo service lightdm stop', then run a bash version of my script with systemd-inhibit, and close the lid, it does halt completely my laptop. So it appears that there's something with lightdm (or something running on it) that is preventing my laptop from turning off when the lid is closed.

At this point I think I could just kill lightdm and run my script when I'm done working... still, it would be nice if don't have to. I mean, it's seems odd to me that I cannot turn off my laptop when the lid is closed without having to stop lightdm.

Thank you very much for your message, regards

Offline

#7 2020-01-16 16:03:34

johnplayer
Member
Registered: 2020-01-16
Posts: 1

Re: Laptop won't shutdown when the lid is closed

I think it is bug in xfce, because when I look into power manager settings where it asks what to do when lid is closed - option shutdown is absent. They simply forgot to add that. Hope someone will register and correct this bug.

You may do workaround for this bug:
"sudo gedit /etc/systemd/logind.conf"

then uncomment HandleLidSwitch and LidSwitchIgnoreInhibited

and rewrite "HandleLidSwitch=poweroff" and "LidSwitchIgnoreInhibited=no"

then "systemctl restart systemd-logind.service"

not sure do some update rewrite this config or not.

Last edited by johnplayer (2020-01-16 17:20:46)

Offline

Board footer

Powered by FluxBB