[systemd-devel] Antw: Re: Re: [EXT] Re: Q: Querying units for "what provides" a target

Michael Biebl mbiebl at gmail.com
Fri Sep 9 12:15:06 UTC 2022


Am Fr., 9. Sept. 2022 um 14:12 Uhr schrieb Michael Biebl <mbiebl at gmail.com>:
>
> Am Fr., 9. Sept. 2022 um 14:01 Uhr schrieb Ulrich Windl
> <Ulrich.Windl at rz.uni-regensburg.de>:
> >
> > >>> Andrei Borzenkov <arvidjaar at gmail.com> schrieb am 09.09.2022 um 13:41 in
> > Nachricht
> > <CAA91j0VQADw8g5mmoFUOvy=YLF666Z_Y9uqYDgTfnmhSBne3rw at mail.gmail.com>:
> > > On Fri, Sep 9, 2022 at 2:13 PM Ulrich Windl
> > > <Ulrich.Windl at rz.uni-regensburg.de> wrote:
> > > ...
> > >> >
> > >> > If you are interested in services that pull in e.g. time-sync.target
> > >> > via Wants (or Requires) and order themselves before the target, you
> > >> > can use something like
> > >> > $ systemctl show time-sync.target -p WantedBy -p RequiredBy -p After
> > >> > RequiredBy=
> > >> > WantedBy=chrony.service
> > >> > After=chrony.service time-set.target
> > >>
> > >> It seems what I wanted to know is output by
> > >> # systemctl show -p After time-set.target
> > >> After=systemd-timesyncd.service
> > >> # systemctl show -p After time-sync.target
> > >> After=time-set.target ntp-wait.service
> > >>
> > >> However the "After=" is somewhat unexpected.
> > >
> > > This is exactly what targets are about. The only usage for targets is
> > > to wait until something else becomes active and to do it they must
> > > come After something.
> > >
> > >> And "-p WantedBy" is definitely
> > >> wrong (it will output units that "require the target", not the units
> > > "providing
> > >> the target").
> > >>
> > >
> > > There is no such thing as "units providing the target". Systemd
> > > documentation makes distinction between targets that Want other units
> > > ("active") and targets that are WantedBy other units ("passive"). It
> > > is expected that services "providing" passive targets have
> > > WantedBy=this-passive.target, otherwise passive targets will not be
> > > activated at all. So WantedBy is exactly correct in this case.
> >
> > Hi!
> >
> > But when I include it (as suggested) I get:
> > # systemctl show  -p WantedBy -p RequiredBy -p After time-sync.target
> > RequiredBy=
> > WantedBy=iotwatch at ROOT.service iotwatch at VPM.service iotwatch-generator.service ntp-wait.service systemd-timesyncd.service
> > After=time-set.target ntp-wait.service
> > ---
> >
> > Those iotwatch* units use "Before="; so is the WantedBy= incorrect for those?
> >
> > Those units use:
> > Wants=nss-user-lookup.target time-sync.target paths.target
> > After=nss-user-lookup.target time-sync.target paths.target
>
>
> See man systemd.special, passive and active targets (as Andrei already
> hinted at).
> Quoting the relevant parts
> "   Special Passive System Units
>        A number of special system targets are defined that can be used
> to properly order boot-up of optional services. These targets are
> generally not part of the initial boot transaction, unless they are
> explicitly pulled in by one of the implementing
>        services. Note specifically that these passive target units are
> generally not pulled in by the consumer of a service, but by the
> provider of the service.
> "
>  iotwatch* does appear to be a consumer of the time-sync.target, so it
> should merely have an ordering but not pull in the target.

Quoting the rest of the man page section:
"
This means: a consuming service should order itself after these
targets (as appropriate), but not
 pull it in. A providing service should order itself before these
targets (as appropriate) and pull it in (via a Wants= type
dependency).
"


More information about the systemd-devel mailing list