5

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.)

5

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.

1
  • Any chance you know how to apply this to user services?
    – fho
    Oct 16 '18 at 8:38
1

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.