[systemd-devel] systemctl start second.service first.service

Andrei Borzenkov arvidjaar at gmail.com
Fri Jan 12 07:11:09 UTC 2018


On Fri, Jan 12, 2018 at 7:51 AM, 林自均 <johnlinp at gmail.com> wrote:
> Hi Andrei,
>
>> If unit A can be started without unit B, why does it matter in which order
>> they are started?
>
> Are you suggesting that After=/Before= must come with Requires= or similar?

What I say is - After/Before is only used when units are activated
concurrently. If activation of unit A requires that unit B is already
active, using Requires is the most straightforward way to achieve it.
If activation of unit A does not require active unit B - why do you
bother with ordering in the first place?

> I think this breaks the design of making ordering dependencies and
> requirement dependencies orthogonal.
>

How do you come to this conclusion?

The way systemd works is

1. it gets request to activate unit
2. it computes additional units that need to be (de-)activated
following chain of Requires/Wants/Conflicts/...
3. it submits internally additional requests to (de-)activate units
collected at previous step
4. it is using After/Before to decide when to actually execute each request

This looks pretty much orthogonal to me (and notice how I avoided
usage of "job" anywhere) :) Requires et al determine *what* to start
and After/Before determine *when* to start.

> Take smbd.service and nmbd.service for example. smbd.service specifies
> After=nmbd.service, but no requirement dependencies on nmbd.service. It
> means that the 2 services can live without each other, but when the two
> services are starting together, ordering matters.
>

If smbd *needs* nmbd it must also ensure that nmbd is always started
when smbd is started. There could be other ways to ensure it, but most
often people think in terms of boot and shutdown, where this
assumption is true (all "enabled" services are added to initial
transaction). As soon as you allow each service to be managed
individually, you are responsible for expressing proper dependencies;
simple "WantedBy=default.target" is no more enough.

Otherwise either After is redundant or unit definition is incomplete (buggy).

> John Lin
>
> Andrei Borzenkov <arvidjaar at gmail.com> 於 2018年1月12日 週五 上午11:59寫道:
>>
>> 12.01.2018 03:47, 林自均 пишет:
>> > How about adding an "--order" option to systemctl? With this option,
>> > systemctl will sort those units by ordering dependencies before
>> > submitting
>> > them.
>>
>> And why does it matter? If unit A can be started without unit B, why
>> does it matter in which order they are started? If unit A can *not* be
>> started without unit B, it must tell so using Requires or Requisite.
>>
>> What are you trying to achieve?


More information about the systemd-devel mailing list