The definition given in the man for systemd unit is a bit unclear: https://www.freedesktop.org/software/systemd/man/systemd.unit.html
If a unit
foo.service
contains a settingBefore=bar.service
and both units are being started,bar.service
's start-up is delayed untilfoo.service
is started up. [...]After=
is the inverse ofBefore=
, i.e. whileAfter=
ensures that the configured unit is started after the listed unit finished starting up,Before=
ensures the opposite, that the configured unit is fully started up before the listed unit is started.
Lets say I have a.service
and b.service
. I want a.service
to start up completely before b.service
because b.service
depends on a.service
.
After reading the aforementioned man page I couldn't find any conclusive explanation on whether:
- You only need to specify
Before=b.service
in thea.service
unit file - You only need to specify
After=a.service
in theb.service
unit file - You need both
After=a.service
in theb.service
unit file andBefore=b.service
in thea.service
unit file
Which do I need to declare dependencies for systemd unit files? Does it matter?
b
depends ona
, aren't you looking forWants
orRequires
orRequisite
anyway?Requires
as I need a hard fail forb
ifa
hasn't started. However according to the aforementioned man page: ` If a unit foo.service requires a unit bar.service as configured with Requires= and no ordering is configured with After= or Before=, then both units will be started simultaneously and without any delay between them if foo.service is activated. `a
andb
example units; no need to wait until you’ve finished translating all your upstart jobs!