0

Let's say a unit (Unit1) has the following unit file configuration:

[Unit]
Wants=Unit2
Before=Unit2

I read Wants as "Unit1, when started, will try to run Unit2 (but it's ok if it fails)".

I read Before as "Unit1 should be started before Unit2".

If the Wants makes Unit2 (try to) start before Unit1, but the Before makes Unit1 start before Unit2, what exactly is the reality? What happens here?

Thanks in advance!

Thomas Stringer
  • 229
  • 1
  • 2
  • 8

1 Answers1

1

From man systemd.unit:

If a unit foo.service contains a setting Before=bar.service and both units are being started, bar.service's start-up is delayed until foo.service has finished starting up. Note that this setting is independent of and orthogonal to the requirement dependencies as configured by Requires=, Wants= or BindsTo=.

Note: independent and orthogonal.

And:

Wants= A weaker version of Requires=. Units listed in this option will be started if the configuring unit is.

This says nothing about causing Unit2 to be started before Unit1. All it means is that when starting Unit1 is set to be started, Unit2 will be set to be started as well, but it doesn't mean that starting Unit2 will be finished before, after or while Unit1 is started. That ordering is set by Before, which will cause the startup of Unit2 to be delayed until Unit1 has finished starting up.

muru
  • 69,900
  • 13
  • 192
  • 292