You are not logged in.

#1 2017-02-12 20:09:39

Phalkon
Member
Registered: 2014-10-19
Posts: 117

need lightdm to suspend system

I need lightdm to suspend the system after say 10 minutes if no user is logged in or if the screen is locked and no password was given to unlock it.

Currently, if I startup the system but won't login, the system stays on and won't suspend after a period of no input.
Also, when the system is accidentally woken up from suspend, but no password is given to unlock it, it won't suspend again.

I use xfce as a DE. Xfpm to setup when to suspend the system. Modified xflock4 script locks the screen with 'dm-tool lock' before suspending.

Last edited by Phalkon (2017-02-19 13:34:38)


Why Linux? Because it doesn't hide anything from you. It puts you so closely in control of your machine that you can feel its heartbeat.

Offline

#2 2017-02-13 12:37:16

seth
Member
Registered: 2012-09-03
Posts: 49,954

Re: need lightdm to suspend system

google for "logind idleaction"

Online

#3 2017-02-15 11:09:59

Phalkon
Member
Registered: 2014-10-19
Posts: 117

Re: need lightdm to suspend system

For some reason this does not work. At first I edited /etc/systemd/logind.conf and restarted systemd-logind.service.
Then I tried to reboot the whole system, but that didn't help either.

My /etc/systemd/logind.conf

IdleAction=suspend
IdleActionSec=1min

default for IdleActionSec was 30min, so I suppose I can use values in minutes.

phalkon ~ $  sudo systemctl status systemd-logind.service
[sudo] password for phalkon: 
● systemd-logind.service - Login Service
   Loaded: loaded (/usr/lib/systemd/system/systemd-logind.service; static; vendor preset: disabled)
   Active: active (running) since Wed 2017-02-15 11:50:45 CET; 14min ago
     Docs: man:systemd-logind.service(8)
           man:logind.conf(5)
           http://www.freedesktop.org/wiki/Software/systemd/logind
           http://www.freedesktop.org/wiki/Software/systemd/multiseat
 Main PID: 460 (systemd-logind)
   Status: "Processing requests..."
    Tasks: 1 (limit: 4915)
   CGroup: /system.slice/systemd-logind.service
           └─460 /usr/lib/systemd/systemd-logind

Feb 15 11:50:45 HAL9000 systemd-logind[460]: Watching system buttons on /dev/input/event4 (Power But
Feb 15 11:50:45 HAL9000 systemd-logind[460]: Watching system buttons on /dev/input/event5 (Video Bus
Feb 15 11:50:45 HAL9000 systemd-logind[460]: Watching system buttons on /dev/input/event6 (Video Bus
Feb 15 11:50:45 HAL9000 systemd-logind[460]: Watching system buttons on /dev/input/event1 (Power But
Feb 15 11:50:45 HAL9000 systemd-logind[460]: Watching system buttons on /dev/input/event2 (Lid Switc
Feb 15 11:50:45 HAL9000 systemd-logind[460]: Watching system buttons on /dev/input/event3 (Sleep But
Feb 15 11:50:45 HAL9000 systemd-logind[460]: Watching system buttons on /dev/input/event12 (Acer WMI
Feb 15 11:50:52 HAL9000 systemd-logind[460]: New session c1 of user lightdm.
Feb 15 11:53:32 HAL9000 systemd-logind[460]: Removed session c1.
Feb 15 11:53:32 HAL9000 systemd-logind[460]: New session c2 of user phalkon.

As you can see in this log I waited almost 3 minutes before logging in, which should be enough for the system to suspend.

It won't suspend the system when nobody is logged in nor when the screen is locked.
Also, as I understand it, it should suspend the system even when I'm logged in and the screen isn't locked, but that also doesn't work.

I use modified lightson script for setting xfpm into presentation mode to prevent system from suspend while watching youtube videos.
I assume logind would ignore xfce presentation mode if it worked properly, wouldn't it?


EDIT: Forgot to mention that I have no other config files mentioned in logind.conf man page that could override the settings.

Last edited by Phalkon (2017-02-15 11:15:29)


Why Linux? Because it doesn't hide anything from you. It puts you so closely in control of your machine that you can feel its heartbeat.

Offline

#4 2017-02-15 17:34:30

seth
Member
Registered: 2012-09-03
Posts: 49,954

Re: need lightdm to suspend system

Why is there a lightdm session? Is lightdm even the active VT?
There's been a lot of hassle with this feature (it's lennartware at its best, yeah, ban me) not working in either direction, but you can only expect it on a VT or if the DE feeds information into it (ie. if you're running gdm/gnome)

Or did I get your post wrong and you want the DM to suspend the system on idleness? (I thought you need to invoke it and wanted to get rid of it)
https://joeyh.name/code/sleepd/ used to provide this, but is now unmaintained (will likely still work, though)

Online

#5 2017-02-15 23:41:50

Phalkon
Member
Registered: 2014-10-19
Posts: 117

Re: need lightdm to suspend system

I use xfpm (power manager on XFCE) to suspend my system, which works fine.

However, when the screen is locked by lightdm or when nobody is logged in, the system won't suspend.
I need the system to suspend after 10 min idle when the screen is locked by 'dm-tool lock' (lightdm) or when no user is logged in, but lightdm is running.

The 'no user logged in' part is not that important as I'm logged in most of the time.
But it does happen that I accidentally wake up the system from sleep, but then I do not enter any password. The system is idle on lightdm password prompt for locked screen and will never suspend again.

Last edited by Phalkon (2017-02-15 23:44:16)


Why Linux? Because it doesn't hide anything from you. It puts you so closely in control of your machine that you can feel its heartbeat.

Offline

#6 2017-02-16 20:08:59

seth
Member
Registered: 2012-09-03
Posts: 49,954

Re: need lightdm to suspend system

Ok, sorry.
Sounds like lightm inhibits the power saving, this bug (i quickly googled up) suggests similar:
https://bugs.launchpad.net/ubuntu/+sour … ug/1307545

If lightdm uses the systemd infrastructure (and doesn't talk to xfpm directly) you should be able to confirm this with "systemd-inhibit --list"

You might be able to mitigate this behavior using the "greeter-setup-script" and "session-setup-script " keys in the lightdm config where the first would start a script to sleep 10 minutes and the suspend where the latter would kill that script again. (This however ignores interaction w/ lightm, but it will take only few seconds to enter credentials)

Notice that I do not know whether that works when using lightm to "lock" the session as well.

Online

#7 2017-02-18 21:07:35

Phalkon
Member
Registered: 2014-10-19
Posts: 117

Re: need lightdm to suspend system

seth wrote:

You might be able to mitigate this behavior using the "greeter-setup-script" and "session-setup-script " keys in the lightdm config where the first would start a script to sleep 10 minutes and the suspend where the latter would kill that script again.

Yes I thought about this too actually, but haven't figured out how to make it run as I need to.

At first, I used this script:

sleep 60 && systemctl suspend

That worked, but it only suspended the system once, before putting the password in and locking it back again.
So if I would woke it by accident more than once, it wouldn't help.

Then I tried to make a loop

while :
do
    sleep 60
    systemctl suspend
done

But now the greeter wouldn't even start as it always waited for the loop to finish (which would never happen). So I was only waking the system up periodically to a black screen.

Then I tried to "run the script in the background".

greeter-setup-script='/opt/lightdm_sleep.sh &'

Which got me a flickering black screen.

I'm not very skilled in bash scripting. Is there a way to make this work?


Why Linux? Because it doesn't hide anything from you. It puts you so closely in control of your machine that you can feel its heartbeat.

Offline

#8 2017-02-18 21:25:44

seth
Member
Registered: 2012-09-03
Posts: 49,954

Re: need lightdm to suspend system

Try to fork inside the script:

#!/bin/sh
(while true; do sleep 60; systemctl suspend; done) &

For the trailing "&" in the config to work, lightdm would have to intepret it (like any shell interpreter), eg. by calling the *script* (not "command") through a wrapping shell.

ooc, did you check whether lightdm inhibits systemd?

Online

#9 2017-02-19 00:02:00

Phalkon
Member
Registered: 2014-10-19
Posts: 117

Re: need lightdm to suspend system

seth wrote:

did you check whether lightdm inhibits systemd?

Yes and it doesn't. Or at least it shouldn't. big_smile
But I checked it while logged in too and there is xfpm listed to inhibite closing of the lid. But I know it doesn't so who knows how the inhibiting works. It seems buggy.

seth wrote:

Try to fork inside the script:

#!/bin/sh
(while true; do sleep 60; systemctl suspend; done) &

Thanks, that worked. big_smile

Well I guess the issue is solved.
Thank you for your help, seth. smile

Last edited by Phalkon (2017-02-19 00:20:54)


Why Linux? Because it doesn't hide anything from you. It puts you so closely in control of your machine that you can feel its heartbeat.

Offline

#10 2017-02-19 13:40:42

Phalkon
Member
Registered: 2014-10-19
Posts: 117

Re: need lightdm to suspend system

I've just changed the status. It's not quite solved yet.

I have a problem with killing the script after logging in.

At first I tried to put the killall command in session-setup-script, but the command kept failing forcing the lightdm to restart spawning new loops of the suspend script.

session-setup-script='killall lightdm_sleep.sh'

Secondly, I tried to make a script out of it. Now I can login again, but suspend script is not killed. I have no idea why.

#!/bin/bash

killall lightdm_sleep.sh

EDIT: When I try to kill the lightdm_sleep.sh from terminal, I need root privileges as the script was run as root by lightdm. But lightdm should run the second script as root too, so that shouldn't be a problem.

Last edited by Phalkon (2017-02-19 13:45:42)


Why Linux? Because it doesn't hide anything from you. It puts you so closely in control of your machine that you can feel its heartbeat.

Offline

#11 2017-02-19 14:47:04

seth
Member
Registered: 2012-09-03
Posts: 49,954

Re: need lightdm to suspend system

Because you got a forked subshell child process, try "killall -g". Also ensure to flag the second script executable.
Instead of killall you may also store the scripts PID

#!/bin/sh
(while true; do sleep 60; systemctl suspend; done) &
echo $! > /tmp/unique_identifier
#!/bin/sh
kill -- -`cat /tmp/unique_identifier`

notice the weird dash row!

Remaining task will be to find a unique and assigned filename, but if you've only one lightdm process running, you can just name it "lightdm_suspend_pid" or so.

Online

#12 2017-02-19 16:27:04

Phalkon
Member
Registered: 2014-10-19
Posts: 117

Re: need lightdm to suspend system

Ok, thanks, but I think I figured out where the problem is.
Killall works, but only if I'm logging in. When I'm already logged in, but the screen is locked, killall script won't be run as it is only run on a session startup and the session was already started.

I have no idea how to solve this without being forced to manually kill the script everytime I unlock the screen. big_smile


Why Linux? Because it doesn't hide anything from you. It puts you so closely in control of your machine that you can feel its heartbeat.

Offline

#13 2017-02-19 16:49:52

Phalkon
Member
Registered: 2014-10-19
Posts: 117

Re: need lightdm to suspend system

How about using the greeter-wrapper?
Does wrapper mean it will be killed with the greeter as soon as I log in?

The script would certainly have to be modified somehow. Currently it won't let the greeter start. I have no idea how to make a wrapper script though.

Last edited by Phalkon (2017-02-19 16:58:59)


Why Linux? Because it doesn't hide anything from you. It puts you so closely in control of your machine that you can feel its heartbeat.

Offline

#14 2017-02-20 16:10:34

seth
Member
Registered: 2012-09-03
Posts: 49,954

Re: need lightdm to suspend system

I've no experience with either lightdm nor light-locker, but the latter looks like being a daemon which is triggerd by some "light-locker-command".
In that case you'll likely not be lucky using a "wrapper" because there's no closing end of the wrap (which you need to kill your script)

Ideally that darn thing would not inhibit anything, but it seems that "light-locker-command -q" queries the locking state, so you could have a watchdog (cron job, ever running script, ...) that queries the lock state and kills the suspend script.

Ever looked into an alternative locker like i3lock?

Online

#15 2017-05-12 19:57:41

boyi
Member
Registered: 2017-05-12
Posts: 1

Re: need lightdm to suspend system

My system uses lightdm for log in, log out  and switch user.  I do not use lightdm for lock screen. I am able to suspend the system for one user. Not sure if it can be used for multiple users.
In the beginning, I use the above codes with slight modification, but was not able to kill the process if I 'switch user', suspend and log back in.  I am able to kill by adding

session-cleanup-script=/usr/share/lightdm_kill_sleep.sh &

It seems like need to have that if the user is still active e.g. like when switch but log back in. Is that the same as lock screen in your situation?

The modifications are as below (I am a newbie thus some lines could be simplified further):

#!/bin/sh
# lightdm_sleep.sh

file="/tmp/unique_identifier"
(while true; do sleep 60; systemctl suspend; done) &
echo $! > $file
#!/bin/sh

# lightdm_kill_sleep.sh
file="/tmp/unique_identifier"
if [ -f "$file" ]
then
    kill `cat $file` 
    rm $file
fi
# in lightdm.conf
greeter-setup-script =/usr/share/lightdm_sleep.sh & 
session-setup-script =/usr/share/lightdm_kill_sleep.sh & 
session-cleanup-script=/usr/share/lightdm_kill_sleep.sh & 

So far the system behave as I expected.

Last edited by boyi (2017-05-12 20:01:33)

Offline

Board footer

Powered by FluxBB