Translates systemd-system lock/sleep signals into systemd-user target activations.
Wait for PrepareForSleep(false) before re-inhibiting
Automatically restart service on failure
Check error of releasing lock



You can also use your local clone with git send-email.


Source | Issues | Patches | Chat

builds.sr.ht status

logind (part of systemd) emits events when the system is locked, unlocked or goes into sleep.

These events however, are simple D-Bus events, and don't actually run anything. There are no facilities for users to easily run anything on these events either (e.g.: a screen locker).

systemd-lock-handler is a small, lightweight helper fills this gap.

When the system is either locked, unlocked, or about to go into sleep, this service will start the lock.target, unlock.target and sleep.target systemd user targets respectively.

When the system is unlocked, lock-target will be stopped.

Any service can be configured to start with any of these targets:

  • A screen locker.
  • A service that keeps the screen off after 15 seconds of inactivity.
  • A service that turns the volume to 0%.
  • ...

Note that systemd already has a sleep.target, however, that's a system-level target, and your user-level units can't rely on it. The one included in this package does not conflict, but rather compliments that one.


#On ArchLinux

A package is available in the AUR:

paru -S systemd-lock-handler

#Other platforms

You can manually build and install:

cd systemd-lock-handler
make build
sudo make install


The service itself must be enabled for the current user:

systemctl --user enable --now systemd-lock-handler.service

Additionally, service files must be created and enabled for any service that should start when the system is locked.

For example, enabling this service file would run swaylock when logind locks the session and before the system goes to sleep:

Description=Screen locker for Wayland
# If swaylock exits cleanly, unlock the session:
# When lock.target is stopped, stops this too:
# Delay lock.target until this service is ready:

# systemd will consider this service started when swaylock forks...
# ... and swaylock will fork only after it has locked the screen.
ExecStart=/usr/bin/swaylock -f
# If swaylock crashes, always restart it immediately:


Specifying PartOf=lock.target indicates to systemd that this service should be stopped if lock.target is stopped. This is even more important for services that aren't the screen locker, since this setting means they'll get stopped when the system is unlocked.

Specifying WantedBy=lock.target will have this service run when locking or sleeping the system.

Specifying WantedBy=sleep.target will have this service run only when sleeping the system. Note that the service will continue running after waking up from sleep.


Lock your session using loginctl lock-session.

This will mark the session as locked, and start lock.target along with any services that are WantedBy it.


Unlock your session using loginctl unlock-session.

This will mark the session as unlocked, start unlock.target, and stop lock.target.

Service that are marked PartOf=lock.target will be stopped when lock.target stops.


Sleep your device using systemctl suspend.

This will start sleep.target along with any services that are WantedBy it. This will happen before the system is suspended.



  • Fixed regression introduced in 2.4.0.


  • Sleeping will be now inhibited when systemd-lock-handler starts. This ensure that there is enough time to react before the system actually goes to sleep. See this article for some background on how this. See also the updated example in the README to ensure that your screen locker has actually locked the screen before sleeping continues.


  • sleep.target now requires lock.target itself. So for any services that should be started when either locking or suspending the system, specifying WantedBy=lock.target is enough.
  • Fixed a bug where lock some services wouldn't be stopped after waking up and then unlocking a system.


  • Also handle unlock events (and translate those to unlock.target).


  • Minor bugfixes.
  • Run as Type=notify.


  • Rewrite in go.
  • Move binary into /usr/lib.


  • Use newer logind API.
  • Events for other sessions are now correctly ignored.


Also handle sleep target.


Initial release.


systemd-lock-handler is licensed under the ISC licence. See LICENCE for details.