[systemd-devel] Help regarding service dependency

Lennart Poettering lennart at poettering.net
Mon Mar 24 14:49:08 PDT 2014


On Thu, 13.03.14 21:25, Amit Saha (asaha at redhat.com) wrote:

> Hello,
> 
> We have service1 which starts in default.target, and we want it to start After service2 
> (systemd-readahead-done) which starts after the default.target is reached. 
> So, I think what would happen in this case is the After=service2 for service1 is ignored
> and it is started before service2 since the default.target must be reached.
> 
> For more specific info, here is a snippet of the .timer file for service2:
> 
> [Unit]
> Description=Stop Read-Ahead Data Collection 10s After Completed Startup
> Documentation=man:systemd-readahead-replay.service(8)
> DefaultDependencies=no
> Conflicts=shutdown.target
> After=default.target
> Before=shutdown.target
> ConditionVirtualization=no
> 
> [Timer]
> OnActiveSec=30s
> 
> 
> A colleague suggested creating a new target for service1 which 
> the system boots into and has a After=default.target, systemd-readahead-done.service.
> Even if not exactly how I mention, this idea holds promise.
> 
> Also, is there any other suggested solution involving fiddling with the unit dependencies
> but not the system boot target?

Note entirely sure I grok what you want to do, but note that if a unit
is pulled in by a target unit via Wants= and both the unit and the
target unit DefaultDependencies=yes (which is the default), then you
will implicitly get an After= added too, so that the target unit is only
reached after the unit is started. 

Or in other words: if you want to order a unit foo.service *after* a
target bar.target you want to pull it in from, then you need to set
DefaultDependencies=no and After=bar.target in it.

The unit you listed above does exactly that, if you look closely.

Lennart

-- 
Lennart Poettering, Red Hat


More information about the systemd-devel mailing list