You are not logged in.
Quick background: I'm using i3lock-blur as a screen locker, and compton as a compositor for transparency. The two conflict with each other, so my solution was to write the following lock script:
#! /bin/bash
killall compton
i3lock -nf
/usr/bin/compton &This works fine by itself, but I am trying to lock the screen when waking up from a suspended state. I have the following systemd unit file:
# /etc/systemd/system/resume@.service
[Unit]
Description=Lock screen after wakeup
After=suspend.target
[Service]
User=%i
Type=forking
Environment=DISPLAY=:0
ExecStart=/bin/bash /home/timourf/bin/lockscreen
[Install]
WantedBy=suspend.targetThis works fine the first time, but leaves compton running in the background as part of the service. Then, if I suspend and resume a second time, it doesn't get invoked again because it's already active. The only fix I've come up with is to run the lock script by itself before suspending, so that the service becomes inactive and gets restarted with suspend.target.
[timourf@Tiberius bin]$ systemctl status resume@timourf
● resume@timourf.service - Lock screen after wakeup
Loaded: loaded (/etc/systemd/system/resume@.service; indirect; vendor preset: disabled)
Active: active (running) since Mon 2018-02-12 13:45:22 CET; 2s ago
Process: 5590 ExecStart=/bin/bash /home/timourf/bin/lockscreen (code=exited, status=0/SUCCESS)
Main PID: 5772 (compton)
Tasks: 1 (limit: 4915)
CGroup: /system.slice/system-resume.slice/resume@timourf.service
└─5772 /usr/bin/comptonI'm looking for a way to restart this service when suspend.target becomes active. I've read the man page for systemd.unit and ruled out the following unit file rules for the following reasons, but I don't know where to go next:
RequiredBy= and WantedBy= don't restart the service if it's already active
BindsTo= and PartOf= are too strong, and kill the process when suspend.target finishes
Last edited by timourf (2018-02-16 17:12:10)
Offline
If you use:
Type=oneshot
does it change something?
The service should not stay active then.
Offline
Alas, no. For the same reason that BindsTo= and PartOf= were not suitable solutions, when the service becomes inactive, compton is killed and no longer runs in the background. I need either a way to keep it active and restart it on suspend.target, or a way to detach the compton process and let it run on its own in the background.
Offline
I don't know if this will work, but you can try to add:
RemainAfterExit=no
in the resume service.
Offline
No luck, same behavior. On one hand, "no" is the default if RemainAfterExit= is not specified, so it shouldn't make a difference. On the other hand, the process isn't supposed to exit in the first place, because compton continues to run in the background like a traditional daemon.
Offline
Is there a particular reason not to use a hook in /usr/lib/systemd/system-sleep/ ?
Offline
Is there a particular reason not to use a hook in /usr/lib/systemd/system-sleep/ ?
No particular reason, other than that service files are mentioned first on the the wiki. I gave your suggestion a shot with the sample script from the wiki, but the call to i3lock cannot connect to X11 (even when I explicitly set DISPLAY in the script). This, I was at least able to do sometimes with the service file.
#!/bin/sh
case $1 in
pre)
killall compton
echo "locking now"
DISPLAY=:0
i3lock -nf
echo "locking done"
compton &
;;
post)
echo "Screen should be locked at this point..."
;;
esacFeb 14 18:03:47 Tiberius systemd[1]: Reached target Sleep.
Feb 14 18:03:47 Tiberius systemd[1]: Starting Suspend...
Feb 14 18:03:47 Tiberius systemd-sleep[24052]: compton: no process found #from killall compton
Feb 14 18:03:47 Tiberius systemd-sleep[24052]: locking now #debug echo
Feb 14 18:03:47 Tiberius systemd-sleep[24052]: i3lock: Could not connect to X11, maybe you need to set DISPLAY?
Feb 14 18:03:47 Tiberius systemd-sleep[24052]: locking done #debug echo
Feb 14 18:03:47 Tiberius systemd-sleep[24052]: Suspending system...
Feb 14 18:03:47 Tiberius kernel: PM: suspend entry (deep)
Feb 14 18:03:47 Tiberius systemd-sleep[24052]: session_init(): Can't open display.
Feb 14 18:03:47 Tiberius systemd-sleep[24052]: session_init(): Can't open display.
Feb 14 18:03:51 Tiberius kernel: PM: Syncing filesystems ... done.
Feb 14 18:03:51 Tiberius kernel: Freezing user space processes ... (elapsed 0.001 seconds) done.
Feb 14 18:03:51 Tiberius kernel: OOM killer disabled.
Feb 14 18:03:51 Tiberius kernel: Freezing remaining freezable tasks ... (elapsed 0.001 seconds) done.
Feb 14 18:03:51 Tiberius kernel: Suspending console(s) (use no_console_suspend to debug)
Offline
try injecting an "export" somewhere ;-)
Edit: also you probably want to run the (blocking) i3lock and the following compton in the "post" hook
Last edited by seth (2018-02-14 17:54:20)
Offline
Okay, so with the help of a friend I was able to resolve the issue, but not in a way that would generalize. In order to get around the problem of the compton process leaving the service running in the background, we thought about ways to detach compton entirely. nohup and disown did not work, but the solution that did was to launch it through my window manager (i3). I modified the same unit file, but removed the call to the script and called everything directly in the pre, start, and post fields.
# /etc/systemd/system/resume@.service
[Unit]
Description=Lock screen after wakeup
Before=suspend.target
[Service]
User=%i
Type=forking
Environment=DISPLAY=:0
ExecStartPre=/usr/bin/killall -q compton
ExecStart=/usr/bin/i3lock -nf
ExecStartPost=/usr/bin/i3 exec compton&
[Install]
WantedBy=suspend.targetIn response to seth,
Edit: also you probably want to run the (blocking) i3lock and the following compton in the "post" hook
the reason for not running it in the post hook is the delay between the screen waking up and the screen locker starting. i3lock takes a fraction of a second to start up, and I prefer seeing it lock just before sleeping rather than after waking up.
Offline