1

I have two services: service A and serviceB. Service A is of the type notify and service B is of type simple. Service B has After=serviceA.service set to ensure service B starts only after service A has sent the notification that it is ready.

I am checking the case when service A exits with non zero code without sending a notification or sending a notification with error like ERRNO=2. Service B waits for service A execution but as soon as service A errors out, service B starts running. Service B should only start running when service A sends READY=1. How can I debug which notification is triggering service B to start execution and also is this expected behavior?

1 Answer 1

1

From man systemd.unit:

After=

... After= ensures [that] the listed unit is fully started up before the configured unit is started. ... start-up is considered completed ... when all its configured start-up commands have been invoked and they either failed or reported start-up success

Therefore, the After= dependency will start serviceB after serviceA has started successfully or failed.

What you are looking for is the combination of:

After=serviceA
Requires=serviceA

From man systemd.unit:

Requires=

... If this unit gets activated, the units listed will be activated as well. If one of the other units fails to activate, and an ordering dependency After= on the failing unit is set, this unit will not be started.

There are a few more tricks to the logic here regarding shutdown. If serviceA finishes cleanly, serviceB will continue running. If serviceA is explicitly stopped or restarted, serviceB will be stopped or restarted.

If you want serviceB to exit when serviceA stops naturally, then use the BindTo= dependency.

You must log in to answer this question.

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