Suppose I have a.service
which I cannot modify, and b.service
which I can modify, I want to see this stop order:
Stopping b.service ...
Stopped b.service
Stopping a.service ...
Stopped a.service
instead of this:
Stopping b.service ...
Stopping a.service ...
Stopped b.service
Stopped a.service
Assume that b.service
may take at least 20 seconds to finish.
Best Answer
In order to stop
b.service
beforea.service
, you need to actually orderb.service
aftera.service
, since the ordering at service stop time is the inverse of the order at start time.So this should be enough to accomplish what you described:
See the documentation for
After=
inman systemd.unit
, which states:You also asked about what happens if
b.service
takes at least 20 seconds to terminate. That is fine. Ifb.service
is properly configured so systemd is able to monitor it until unit stop is completed (in other words, ifExecStop=
is not somehow misconfigured) and if it stops before the timeout is reached (seeTimeoutStopSec=
), then systemd will wait untilb.service
is fully stopped before initializing shutdown ofa.service
.