I have a systemd service that runs a background daemon (xflux) from the user session manager.

When I suspend and resume my computer, it messes up xflux's time reckoning; I have to manually issue systemctl --user restart xflux to fix it.

How can I tell the service to automatically stop before suspend, and start after resume? (I found an answer that automatically runs a given service on resume, but this isn't quite what I want.)

2 Answers 2


You can put an executable file in /lib/systemd/system-sleep/ and it will be run on suspend with the 2 args pre and suspend, and again after resume with post and suspend. The systemd man page says this is a hack.

To use a systemd Unit, see my later answer to a similar question.

  • Any chance you know how to apply this to user services?
    – fho
    Commented Oct 16, 2018 at 8:38

Old thread - however, I stumbled over a similar situation. The requested code snippet should be:

case "$1" in
    su - $USER --shell=/bin/sh -c '
            export XDG_RUNTIME_DIR=/run/user/$(id -u);
            systemctl --user restart xflux

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .