You are not logged in.
Apologies in advance if this is answered already, but I cannot find a solution.
I have a service as follows:
[Unit]
Description=lock on suspend
Before=suspend.target
[Service]
User=xyz123
Environment=DISPLAY=:0
ExecStart=/usr/bin/slock
ExecStartPost=/usr/bin/sleep 2
[Install]
WantedBy=suspend.targetThis is supposed to lock the screen when suspending.
The issue is that on resume, the unlocked screen shows briefly (1 second or less) before the lock starts.
I understood this to be an issue that the ExecStartPost sleep is supposed to work around, where the lock doesn't have time to start before suspend.
But in this case the ExecStartPost sleep doesn't seem to have any effect on this.
What information can I show to help debug this? Here I try to pick out the relevant journalctl entries (not sure if safe to post all the output):
Suspend started:
Mar 21 01:36:07 hp NetworkManager[588]: <info> [1553142967.1010] manager: sleep: sleep requested (sleeping: no enabled: yes)
Mar 21 01:36:07 hp NetworkManager[588]: <info> [1553142967.1011] manager: NetworkManager state is now ASLEEP
Mar 21 01:36:07 hp systemd[1]: Reached target Sleep.
Mar 21 01:36:07 hp systemd[1]: Starting Suspend...
Mar 21 01:36:07 hp systemd[1]: Starting lock on suspend...
Mar 21 01:36:07 hp systemd-sleep[24740]: Suspending system...Resume started:
Mar 21 01:36:15 hp ntpd[615]: Deleting interface #29 wlo1, fe80::1437:f529:66cd:fe16%3#123, interface stats: received=0, sent=0, dropped=0, active_time=690 secs
Mar 21 01:36:15 hp systemd[1]: lock_suspend.service: Succeeded.
Mar 21 01:36:15 hp audit[1]: SERVICE_STOP pid=1 uid=0 auid=4294967295 ses=4294967295 msg='unit=lock_suspend comm="systemd" exe="/usr/lib/systemd/systemd" hostname=? addr=? t>Since it shows that lock_suspend.service succeded AFTER suspend, the problem must be ExecStartPost has no effect... How come?
Offline
This works for me:
# /etc/systemd/system/resume@.service
[Unit]
Description=Lock the screen on resume
[Service]
User=%i
Environment=DISPLAY=:0
ExecStart=/usr/bin/slock
[Install]
WantedBy=suspend.target sleep.target hibernate.target hybrid-sleep.target suspend-then-hibernate.targetNo need for Before=suspend.target or the ExecStartPost delay.
Jin, Jîyan, Azadî
Offline
Thanks for reply. I tried your service, I still get a brief glimpse of my screen on resume. You don't see that at all? What command are you using to suspend? I'm now wondering if there's some other setting forcing too quick suspend, maybe I need a delay somehow.
Offline
I still get a brief glimpse of my screen on resume. You don't see that at all?
I do see a (very) brief flash of the screen if I use systemctl suspend from the command line (and then press the power button to resume) but I don't see that at all if I suspend the machine by closing the laptop lid and then open it.
Last edited by Head_on_a_Stick (2019-03-21 17:51:49)
Jin, Jîyan, Azadî
Offline
Instead of adding a postdelay, what about blanking your screen in an ExecStartPre= e.g.
ExecStartPre=/usr/bin/xset dpms force suspendOffline
Good idea, still see the screen flash. It's like the suspend is just forced regardless of the hooks. Worst case workaround I can use a suspend wrapper that locks the screen then suspends, but I don't like this as I don't trust that wrapper will always be used. Thanks.
Offline