1

Let's say, that I have a systemd service type of unit which contains both following Wants= and After= statements:

Wants=foo.service
After=foo.service

Do I really need to specify the foo.service on Wants= if it is already on After=? Or maybe the Wants=foo.service is needed because if no units specify the foo.service as Wants= or Requires=, then the foo.service is not started at all?

2

It depends, both are possible, both of them do something, but they have a distinct effect, so you'll want to keep the Wants= in cases where you want to make sure the foo.service unit is started whenever your other unit is started.

If you only have an ordering dependency, such as After=foo.service, then that only means that if both units are being started (in the same transaction), then systemd will start foo.service first (and wait until it is completely started) before starting the current unit.

That is useful when you don't necessarily know whether foo.service is enabled or not, your service works either way, but if foo.service is enabled, you would like to have it start before your service.

Or maybe the Wants=foo.service is needed because if no units specify the foo.service as Wants= or Requires=, then the foo.service is not started at all?

Yes, that is correct. The After= and Before= directives are ordering-only directives, so they don't pull the other unit, only affect the ordering if the unit is already being started through other means (usually it being directly enabled itself, or possibly through a Wants= or Requires= dependency on a third unit.)

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.