Based on various sources I have cobbled together ~/.config/systemd/user/screenlock.service
:
[Unit]
Description=Lock X session
Before=sleep.target
[Service]
Environment=DISPLAY=:0
ExecStart=/usr/bin/xautolock -locknow
[Install]
WantedBy=sleep.target
I've enabled it using systemctl --user enable screenlock.service
. But after rebooting, logging in, suspending and resuming (tested both with systemctl suspend
and by closing the lid) the screen is not locked and there is nothing in journalctl --user-unit screenlock.service
. What am I doing wrong?
Running DISPLAY=:0 /usr/bin/xautolock -locknow
locks the screen as expected.
$ systemctl --version
systemd 215
+PAM -AUDIT -SELINUX -IMA -SYSVINIT +LIBCRYPTSETUP +GCRYPT +ACL +XZ +SECCOMP -APPARMOR
$ awesome --version
awesome v3.5.5 (Kansas City Shuffle)
• Build: Apr 11 2014 09:36:33 for x86_64 by gcc version 4.8.2 (nobody@)
• Compiled against Lua 5.2.3 (running with Lua 5.2)
• D-Bus support: ✔
$ slim -v
slim version 1.3.6
If I run systemctl --user start screenlock.service
the screen locks immediately and I get a log message in journalctl --user-unit screenlock.service
, so ExecStart
clearly is correct.
xautolock -locker slock &
Creating a system service with the same file works (that is, slock
is active when resuming):
# ln -s "${HOME}/.config/systemd/user/screenlock.service" /usr/lib/systemd/system/screenlock.service
# systemctl enable screenlock.service
$ systemctl suspend
But I do not want to add a user-specific file outside $HOME
for several reasons:
- User services should be clearly separated from system services
- User services should be controlled without using superuser privileges
- Configuration should be easily version controlled
systemd-user
is still very flaky; getting it to work as part of the session via the approach I outlined would help narrow down the issue; that's all I can suggest./etc/systemd/system/
or$HOME/.local/systemd/system
to avoid putting anything in/usr
manually. As @jasonwryan mentioned, user sessions are still not considered production-quality; but they're getting closer.