1

I have a systemd service named webserver.service that is wanted by multiuser.target (enabled by default on system). I have another service under another target named test.service that I want to run after webserver.service. Within test.servive I’m adding:

After=webserver.service

Is it enough or should I add following require statement as well:

Requires=webserver.service

Tried with just after statement is seems working as expected, just worried about any potential of race during system bootup.

2
  • Does this answer your question? Understanding systemd "Requires=" option
    – muru
    Commented May 24 at 14:18
  • nope, the question here is, if another service or target is already requiring/wanting a service (webserver.service), do I still need to add 'Requires=webserver.service' to a third service (test.service) which is supposed to get started after that (using After=)
    – Denny
    Commented May 24 at 16:33

1 Answer 1

0

Short answer: yes.

Before and After in systemd are interpreted purely for timing, they don't start services. You generally want a Wants or Requires or BindsTo in order to start a service. People rarely have a purely-timing requirement.

Long answer: The Wants link from the Target unit (that was probably installed by the service install section) is enough to start the required service. It's good practice though to capture all the relationships in the unit files. If Service A must have Service B it should Require it even if the service runs on it's own so that a systemctl disable service_b doesn't cause Service A to silently fail later.

5
  • Thanks, even if another enabled service is already requiring / wanting that service?
    – Denny
    Commented May 24 at 16:40
  • 1
    Sorry I misread that. If something else is bringing the other service into the "graph" systemd will just respect the timing.
    – davolfman
    Commented May 24 at 16:49
  • ah ok, thanks. In that case, I don't need "requires=another.service" right?
    – Denny
    Commented May 24 at 16:52
  • 1
    @Denny: You technically don't need it, but if test.service actually relies on webserver running, then you should have it regardless and not rely on "side effects". Commented May 27 at 4:31
  • ah ok, thanks Danny
    – Denny
    Commented May 27 at 14:42

You must log in to answer this question.

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