swaylock: Can't start swaylock on lidclose

Trying to replicate the behavior from i3lock with the following systemd service:

[Unit]
Description=Lock screen on resume from suspend
Before=sleep.target

[Service]
User=kf
Environment=DISPLAY=:0
Type=forking
ExecStart=/usr/bin/swaylock
ExecStartPost=/usr/bin/sleep 1

[Install]
WantedBy=sleep.target

but it is not running… the exact same service runs fine with i3lock. Output from journalctl:

Feb 02 15:13:48 arch systemd-logind[3378]: Lid closed.
Feb 02 15:13:48 arch systemd-logind[3378]: Suspending...
Feb 02 15:13:48 arch systemd[1]: Starting Lock screen on resume from suspend...
-- Subject: A start job for unit lock.service has begun execution
-- Defined-By: systemd
-- Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- A start job for unit lock.service has begun execution.
-- 
-- The job identifier is 1703.
Feb 02 15:13:48 arch swaylock[16317]: error: XDG_RUNTIME_DIR not set in the environment.
Feb 02 15:13:48 arch swaylock[16317]: 2019-02-02 15:13:48 - [swaylock/main.c:1047] Unable to connect to the compositor. If your compositor is running, check or set the WAYLAND_DISPLAY enviro>
Feb 02 15:13:48 arch systemd[1]: lock.service: Main process exited, code=exited, status=1/FAILURE
-- Subject: Unit process exited
-- Defined-By: systemd
-- Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- An ExecStart= process belonging to unit lock.service has exited.
-- 
-- The process' exit code is 'exited' and its exit status is 1.
Feb 02 15:13:49 arch systemd[1]: lock.service: Failed with result 'exit-code'.
-- Subject: Unit failed
-- Defined-By: systemd
-- Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- The unit lock.service has entered the 'failed' state with result 'exit-code'.
Feb 02 15:13:49 arch systemd[1]: Failed to start Lock screen on resume from suspend.
-- Subject: A start job for unit lock.service has failed
-- Defined-By: systemd
-- Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- A start job for unit lock.service has finished with a failure.
-- 
-- The job identifier is 1703 and the job result is failed.
Feb 02 15:13:49 arch systemd[1]: Reached target Sleep.
-- Subject: A start job for unit sleep.target has finished successfully
-- Defined-By: systemd
-- Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- A start job for unit sleep.target has finished successfully.
-- 
-- The job identifier is 1649.
Feb 02 15:13:49 arch systemd[1]: Starting Suspend...
-- Subject: A start job for unit systemd-suspend.service has begun execution
-- Defined-By: systemd
-- Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- A start job for unit systemd-suspend.service has begun execution.
-- 
-- The job identifier is 1646.
Feb 02 15:13:49 arch systemd-sleep[16320]: Suspending system...
-- Subject: System sleep state suspend entered
-- Defined-By: systemd
-- Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- The system has now entered the suspend sleep state.

System Arch Linux 4.14.71-rt44-1-rt-lts, sway version 1.0-beta.2-204-g70637b40 (Jan 17 2019, branch ‘master’), swaylock version 1.2-46-geffdea5 (Feb 1 2019, branch ‘master’)

Am I just messing up the systemd service file, or is there a bug somewhere?

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 21 (5 by maintainers)

Most upvoted comments

I’m getting the same issue but with lock and idle, but run on sway startup instead of systemd.

set $lock_bg ~/Pictures/backgrounds/galen-crout-175291.jpg

bindsym Alt+l exec swaylock -i $lock_bg

exec swayidle -w \
         timeout 300 'swaylock -f -c 000000 -i $lock_bg' \
         timeout 600 'swaymsg "output * dpms off"' \
              resume 'swaymsg "output * dpms on"' \
         before-sleep 'swaylock -f -c 000000 -i $lock_bg'

The issue happens only on suspend-resume. Manually locking or timeout locking is fine.