Systemd user services are a great way to run services as your user for as long as you are logged in or also during the complete uptime of your system. Some people use it for example to manage their mpd. After learning about them, I thought that they would a great way to lock my laptop and mute any music whenever I suspend. Just put a few user services before suspend.target. However, for security reasons user services are not notified of such system targets. My way around this is a system unit user-suspend@.service that forwards any of the interesting targets to my user’s systemd instance.
| |
Then enable it for your user’s id with sudo systemctl enable user-suspend@$(id -u).service and create the following proxy target in ~/.config/systemd/user/suspend.target.
| |
Now you can use suspend.target in your user services the same as in system units.
| |