[systemd-devel] Antw: [EXT] Re: [systemd‑devel] Examples to distinguish Before=/After= and Wants=/Requires=/BindsTo=

2021-10-01 Thread Ulrich Windl
>>> Lennart Poettering  schrieb am 17.09.2021 um 11:49
in
Nachricht :
> On Mi, 15.09.21 17:15, Manuel Wagesreither (man...@fastmail.fm) wrote:
> 
>> Hello all,
>>
>> I'm onboarding some collegues who don't have much experience with
>> systemd. One thing I would like to focus on is the difference
>> between Before=/After= and Wants=/Requires=/BindsTo in systemd
>> units.
>>
>> I think it would get immediately clear if could provide them an
>> example where we want one but not the other. Unfortunately I've got
>> problems coming up with such an example. In my use cases, whenever I
>> needed an After= I needed an Wants= as well.
>>
>> Can you come up with something good?
> 
> Whenever you have a conceptually "weak" dependency between to
> packages, i.e. both services can work alone, but they can also wor
> together, and if so, one should be ordered after the other.
> 
> more specific example: you can use apache without mysql, and you can
> use mysql without apache, but quite often they are used together, and
> if so you likely want to start mysql first, and apache second, since
> it likely consumes services of mysql, and not the other way
> round. Hence in this example, you'd place an ordering dep, but not
> requirement dep.

And another aspect: While you could add the dependencies in mysql as well as
apache, you'd probably do it in apache here (as it is the "consumer"), right?
Or would you place it outside of both?

> 
> Lennart
> 
> ‑‑
> Lennart Poettering, Berlin





[systemd-devel] Antw: [EXT] Re: [systemd‑devel] Examples to distinguish Before=/After= and Wants=/Requires=/BindsTo=

2021-10-01 Thread Ulrich Windl
>>> "Pagliari, Vivenzio (Nokia - DE/Ulm)"  schrieb
am
17.09.2021 um 09:52 in Nachricht


> Hello Manuel,
> 
> my experience is that it is helpful for people new to systemd to "raise the

> right question" that is answered by the corresponding relationship between 
> systemd units.
> 
> The question "*if* a unit shall be started/enqueued" is answered 
> Wants=/Requires=/BindsTo relation. I call this the "dependency relation". To

> know "*when* a unit shall be started/enqueued, you need to consider the 
> Before=/After= relation. I call this is the "time order relation". It is 
> pretty obvious, that a time order relation only makes sense, of you have a 
> dependency relation as well. The other way round it is different: it may
make 
> sense that some unit A wants some other unit B, but there is no time
ordering 
> between them.
> 
> If you have some "mathematically inclined" people whom you want to describe

> it: Given a set A of all systemd units on your computer, you have the
special 
> unit default.target (or the one passed on the kernel command line with the 
> systemd.unit parameter) which forms the root of a "dependency tree", given
by 
> the Requires/Wants relations. This tree forms the subset B of systemd units

> on your computer to be started/enqueued at boot time. This set B of systemd

> units is a partially ordered set: Some (but not all) of the elements have a

> (time) order relation, by which they can be (topologically) sorted. This is

> then the order in which the units are enqueued. Note that this order is not

> "fix", there can be different "total orderings" of a partially ordered set.

Yes, what makes things more complicated is that "After X" actually means
"NotBefore X" (i.e. "at some later time" and not "immediately after X"), and
"Before" means "NotAfter".
Combined with the swapped roles on system startup/shutdown, it can be rather
tricky sometimes to get things right.

Regards,
Ulrich

> 
> HTH
> Vivenzio
> 
> ‑Original Message‑
> From: systemd‑devel  On Behalf
Of 
> Manuel Wagesreither
> Sent: Wednesday, September 15, 2021 5:16 PM
> To: SystemD Devel 
> Subject: [systemd‑devel] Examples to distinguish Before=/After= and 
> Wants=/Requires=/BindsTo=
> 
> Hello all,
> 
> I'm onboarding some collegues who don't have much experience with systemd. 
> One thing I would like to focus on is the difference between Before=/After=

> and Wants=/Requires=/BindsTo in systemd units.
> 
> I think it would get immediately clear if could provide them an example 
> where we want one but not the other. Unfortunately I've got problems coming

> up with such an example. In my use cases, whenever I needed an After= I 
> needed an Wants= as well.
> 
> Can you come up with something good?
> 
> Thanks, regards,
> Manuel