You are not logged in.

#1 2015-01-31 19:28:37

Xenograph
Member
Registered: 2015-01-22
Posts: 9

[Solved] Systemd lock on suspend is delayed

I'm trying to run i3lock upon suspend using this systemd service file:

[Unit]
Description=Screen locker
 
[Service]
User=%I
Type=forking
Environment=DISPLAY=:0
ExecStart=/usr/bin/i3lock
 
[Install]
WantedBy=suspend.target

But the issue I'm having is that the screen lock doesn't actually start, as far as I can tell, until shortly after the computer resumes from suspend. It is such that as the computer resumes, I momentarily see my desktop and can use the mouse/keyboard to do things. This only lasts for less than a second or so before the lock screen appears.

Last edited by Xenograph (2015-01-31 23:40:49)

Offline

#2 2015-01-31 21:12:31

Stebalien
Member
Registered: 2010-04-27
Posts: 1,237
Website

Re: [Solved] Systemd lock on suspend is delayed

Try putting `xhost +si:localuser:root` in your `~/.xinitrc`.


Steven [ web : git ]
GPG:  327B 20CE 21EA 68CF A7748675 7C92 3221 5899 410C
Do not email: honeypot@stebalien.com

Offline

#3 2015-01-31 21:44:17

Xenograph
Member
Registered: 2015-01-22
Posts: 9

Re: [Solved] Systemd lock on suspend is delayed

Stebalien wrote:

Try putting `xhost +si:localuser:root` in your `~/.xinitrc`.

That didn't help.

Offline

#4 2015-01-31 21:55:48

firecat53
Member
From: Lake Stevens, WA, USA
Registered: 2007-05-14
Posts: 1,542
Website

Re: [Solved] Systemd lock on suspend is delayed

You actually want this run in sleep.target (change to WantedBy=sleep.target). Suspend.target is actually the stuff to do on resume; thus the brief flash of desktop. Clear as mud? smile

Scott

Offline

#5 2015-01-31 22:00:39

Xenograph
Member
Registered: 2015-01-22
Posts: 9

Re: [Solved] Systemd lock on suspend is delayed

firecat53 wrote:

You actually want this run in sleep.target (change to WantedBy=sleep.target). Suspend.target is actually the stuff to do on resume; thus the brief flash of desktop. Clear as mud? smile

Scott

I actually already tried both, thinking that might have been the case. Whether I use sleep.target or suspend.target, I get the same problem sad

EDIT: Although I still get the brief flash of desktop, it does seem like I can't do any keyboard/mouse input, so that helps a bit with security though not really aesthetics haha.

Last edited by Xenograph (2015-01-31 22:03:34)

Offline

#6 2015-01-31 22:28:12

Stebalien
Member
Registered: 2010-04-27
Posts: 1,237
Website

Re: [Solved] Systemd lock on suspend is delayed

Xenograph wrote:
Stebalien wrote:

Try putting `xhost +si:localuser:root` in your `~/.xinitrc`.

That didn't help.

Sorry, I totally misread your post. Personally, I hook into loginctl's prepare for sleep signal using a user-service I wrote https://github.com/Stebalien/systemd-user-manager. When run under under a systemd user instance, it will start the user instance's sleep.target and block suspend until the target has started completely. You can use this to pull in i3lock as a user service.


Steven [ web : git ]
GPG:  327B 20CE 21EA 68CF A7748675 7C92 3221 5899 410C
Do not email: honeypot@stebalien.com

Offline

#7 2015-01-31 22:39:06

Xenograph
Member
Registered: 2015-01-22
Posts: 9

Re: [Solved] Systemd lock on suspend is delayed

Stebalien wrote:
Xenograph wrote:
Stebalien wrote:

Try putting `xhost +si:localuser:root` in your `~/.xinitrc`.

That didn't help.

Sorry, I totally misread your post. Personally, I hook into loginctl's prepare for sleep signal using a user-service I wrote https://github.com/Stebalien/systemd-user-manager. When run under under a systemd user instance, it will start the user instance's sleep.target and block suspend until the target has started completely. You can use this to pull in i3lock as a user service.

Ah interesting.. I wish there were an easier way to do it though, one that didn't involve hacks for something as simple as starting a lock screen before suspend.

Last edited by Xenograph (2015-01-31 22:44:20)

Offline

#8 2015-01-31 22:57:45

firecat53
Member
From: Lake Stevens, WA, USA
Registered: 2007-05-14
Posts: 1,542
Website

Re: [Solved] Systemd lock on suspend is delayed

This is the complete unit I've been using successfully for quite some time now. Perhaps the 'Before=sleep.target' line will help you.

/etc/systemd/system/suspend@.service
[Unit]
Description=User suspend actions
Before=sleep.target

[Service]
User=%I
Type=forking
Environment=DISPLAY=:0
Environment=HOME=%h
ExecStartPre= -/usr/bin/mysql -e 'stop slave' ; -/usr/local/bin/music.sh stop ; -/usr/bin/pkill -9 unison
ExecStart=-/usr/bin/i3lock -i /tmp/wall.png

[Install]
WantedBy=sleep.target
# systemctl enable suspend@firecat53.service

Last edited by firecat53 (2015-01-31 22:58:51)

Offline

#9 2015-01-31 23:40:24

Xenograph
Member
Registered: 2015-01-22
Posts: 9

Re: [Solved] Systemd lock on suspend is delayed

Unfortunately, adding Before=sleep.target didn't help. However, I found a fix, sort of. I added 'sleep 1' under 'ExecStartPost' and now the lock screen successfully starts before the system suspends. Marking as solved.

Last edited by Xenograph (2015-01-31 23:40:39)

Offline

Board footer

Powered by FluxBB