0

service B unit configuration (it is an oneshot service):

[Unit]
Description=Service B
After=serviceA.service

service A is disabled by default (it is a simple service)

● serviceA.service - service A
Loaded: loaded (/usr/lib/systemd/system/serviceA.service; disabled; vendor preset: disabled)
Active: inactive (dead)

I would expect service B to not start until service A is started because of the ordering requirement. What I am observing is that service B starts without waiting for service A when machine is booted up. Can anyone explain this

1 Answer 1

0

If you want to start serviceB.service only if serviceA.service is started (and it's running) then you should add: Requisite to your serviceB.service.

From man systemd.unit:

Requisite=

Similar to Requires=. However, if the units listed here are not started already, they will not be started and the starting of this unit will fail immediately. Requisite= does not imply an ordering dependency, even if both units are started in the same transaction. Hence this setting should usually be combined with After=, to ensure this unit is not started before the other unit.

serviceB.service

[Unit]
Description=Service B
After=serviceA.service
Requisite=serviceA.service

[Service]
Type=oneshot
ExecStart=/bin/bash /home/user/somescript.sh

[Install]
WantedBy=multi-user.target

So for example, if you don't enable serviceA.service or this one it's not running when the serviceB.service wants to run then you should get a message like this in the serviceB.service logs:

A dependency job for serviceB.service failed. See 'journalctl -xe' for details.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .