[systemd-devel] Examples to distinguish Before=/After= and Wants=/Requires=/BindsTo=

Pagliari, Vivenzio (Nokia - DE/Ulm) vivenzio.pagliari at nokia.com
Fri Sep 17 07:52:54 UTC 2021


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.

HTH
Vivenzio

-----Original Message-----
From: systemd-devel <systemd-devel-bounces at lists.freedesktop.org> On Behalf Of Manuel Wagesreither
Sent: Wednesday, September 15, 2021 5:16 PM
To: SystemD Devel <systemd-devel at lists.freedesktop.org>
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


More information about the systemd-devel mailing list