You are not logged in.

#1 2014-08-05 01:37:28

jkav77
Member
Registered: 2013-07-11
Posts: 9

[SOLVED] Suspend and lock on lid close with systemd

Suspend on lid close works just fine, but I cannot get the systemd service file to lock the screen on suspend working.  I have seen numerous guides and .service files to do this, but I must be missing something.  Below is my .service file, but when I start it the screen locks immediately and then the service fails.  It never runs when I close the lid, or run "systemctl suspend".  If anyone can help me figure out what I am doing wrong I would really appreciate it.

Note: I have tried xautolock, as below as well as "dm-tool lock".  I have tried both suspend.target and sleep.target.  Most of the guides I have seen show sleep.target, but I don't seem to have that target (see below).  Also, the etc/systemd/logind.conf file has "HandleLidSwitch=suspend".  As far as I can tell, acpid is not running and pm-utils is not even installed.  The desired effect is the locker (any really) is called when the computer suspends.

Service File lidlock.service

[Unit]
Description=Lock X session on lid switch
After=suspend.target

[Service]
User=james
Type=forking
Environment=DISPLAY=:0
ExecStart=/usr/bin/xautolock -locknow

[Install]
WantedBy=suspend.target

Output of "systemctl list-units --type=target"

UNIT                LOAD   ACTIVE SUB    DESCRIPTION
basic.target        loaded active active Basic System
bluetooth.target    loaded active active Bluetooth
cryptsetup.target   loaded active active Encrypted Volumes
getty.target        loaded active active Login Prompts
graphical.target    loaded active active Graphical Interface
local-fs-pre.target loaded active active Local File Systems (Pre)
local-fs.target     loaded active active Local File Systems
multi-user.target   loaded active active Multi-User System
network.target      loaded active active Network
paths.target        loaded active active Paths
remote-fs.target    loaded active active Remote File Systems
slices.target       loaded active active Slices
sockets.target      loaded active active Sockets
sound.target        loaded active active Sound Card
suspend.target      loaded active active Suspend
swap.target         loaded active active Swap
sysinit.target      loaded active active System Initialization
timers.target       loaded active active Timers

Last edited by jkav77 (2014-08-05 19:50:22)

Offline

#2 2014-08-05 01:47:50

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: [SOLVED] Suspend and lock on lid close with systemd

You aren't calling a locker...

This works for me:

[Unit]
Description=Lock the screen on resume from suspend

[Service]
User=jason
Environment=DISPLAY=:0
ExecStart=/usr/bin/slock

[Install]
WantedBy=sleep.target

Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#3 2014-08-05 02:09:18

jkav77
Member
Registered: 2013-07-11
Posts: 9

Re: [SOLVED] Suspend and lock on lid close with systemd

I have used "xautolock -locknow", "dm-tool lock" and I installed slock to duplicate your setup.  I ran the exact service file you posted, except I changed the username.  When I started that service, the screen went blank briefly and then returned to the console.  The service failes (see below).  I am not really sure where to look for information about what the problem is.  The journal does not contain any more information than the service status below.

sudo systemctl status -l lidlock2 output:

● lidlock2.service - Lock the screen on resume from suspend
   Loaded: loaded (/etc/systemd/system/lidlock2.service; disabled)
   Active: failed (Result: exit-code) since Mon 2014-08-04 19:04:32 PDT; 43s ago
  Process: 30232 ExecStart=/usr/bin/slock (code=exited, status=1/FAILURE)
 Main PID: 30232 (code=exited, status=1/FAILURE)

Aug 04 19:04:32 chrutabaga systemd[1]: lidlock2.service: main process exited, code=exited, status=1/FAILURE
Aug 04 19:04:32 chrutabaga systemd[1]: Unit lidlock2.service entered failed state.

service file (same as you gave me):

[Unit]
Description=Lock the screen on resume from suspend

[Service]
User=james
Environment=DISPLAY=:0
ExecStart=/usr/bin/slock

[Install]
WantedBy=sleep.target

Offline

#4 2014-08-05 02:20:00

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: [SOLVED] Suspend and lock on lid close with systemd

If slock is working, then I am not sure why the service would be failing. You did test it outside the service file?


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#5 2014-08-05 02:24:13

jkav77
Member
Registered: 2013-07-11
Posts: 9

Re: [SOLVED] Suspend and lock on lid close with systemd

Yes.  If I run it outside the service file it works as normal.  Black screen, turns blue when you start typing; unlocks when password entered.  But for some reason the service is not working, and the error messages are very generic.  I am not sure what to look at.

Offline

#6 2014-08-05 02:33:28

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: [SOLVED] Suspend and lock on lid close with systemd

What does `systemctl list-units | grep lidlock` show?


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#7 2014-08-05 02:35:49

jkav77
Member
Registered: 2013-07-11
Posts: 9

Re: [SOLVED] Suspend and lock on lid close with systemd

It fails right away.  I'm not sure why.

systemctl list-units | grep lidlock

55:●lidlock2.service                                                                          loaded failed failed    Lock the screen on resume from suspend

Offline

#8 2014-08-05 02:44:17

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: [SOLVED] Suspend and lock on lid close with systemd

I'm at a loss. Remove all the service files/symlinks and start from scratch.


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#9 2014-08-05 03:31:16

halocaridina
Member
From: US
Registered: 2014-07-21
Posts: 77

Re: [SOLVED] Suspend and lock on lid close with systemd

jkav77,

I also found calling a locker (e.g., xautolock, slock) from a .service file in combination with suspend via lid closing to be hit-and-miss. I ended up using:

xss-lock

from the AUR and it works as expected on wake from suspend. Its autostarted from the i3 config file (mod for your own context) like:

exec --no-startup-id xss-lock -- i3lock -b -i /path/to/archlinux.png &

So try clearing out all locker-related service files/symlinks, install xss-lock and give it a try.


4X Intel(R) Xeon(R) CPU E7-8870 @ 2.40GHz; 256GiB; 11TB EXT4; SL6.8
2X Intel(R) Xeon(R) CPU E5-2680 @ 2.70GHz; 256GiB; 3.4TB EXT4; SL6.8
Thinkpad X250; Broadwell-ULT Core i5; 8GiB, 525GB Crucial_CT525MX3; Arch
Thinkpad T440S; Haswell-ULT Core i7; 12GiB, 512GB SanDisk X210; Arch

Offline

#10 2014-08-05 19:49:41

jkav77
Member
Registered: 2013-07-11
Posts: 9

Re: [SOLVED] Suspend and lock on lid close with systemd

@halocaridina,

Thank you for pointing me to this util.  This is now working with slock.  However, it has the undesirable effect that the screen displays for 1-2 seconds after resume when using it with the lightdm locker (dm-tool lock).  I will just abandon using that locker since this is now working and I don't want to put any more time into this.  I added it to my .xprofile so it runs at startup.

Thanks for the help.  I will mark this as solved.

.xprofile

xss-lock -- /usr/bin/slock &

Offline

#11 2016-03-23 03:15:40

antiqiuty
Member
Registered: 2014-09-12
Posts: 11

Re: [SOLVED] Suspend and lock on lid close with systemd

The following works for me with "Type=forking". It seems that xss-lock is not necessary.

[Unit]
Description=i3 lock for suspension

[Service]
User=james
Type=forking
Environment=DISPLAY=:0
ExecStart=/usr/bin/i3lock -p win -d -c 000000

[Install]
WantedBy=sleep.target

Offline

#12 2016-03-23 05:00:54

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: [SOLVED] Suspend and lock on lid close with systemd

Please don't necrobump, especially solved threads: https://wiki.archlinux.org/index.php/Fo … bumping.22


Closing


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

Board footer

Powered by FluxBB