systemd: Requires vs BindsTo?

I have two services running on the same machine, A and B. A is server, B is client

  • A can running alone, but B must have A running before it can start
  • if A crashes, stops, or restarts, B must stop or restart
  • if B crashes, stops, or restarts, A is unaffected and can keep running

In B.service should I use Requires or BindsTo ?

[Unit]
Description=service B
After=A.service
Requires=A.service

or

[Unit]
Description=service B
After=A.service
BindsTo=A.service

Do I need to add the counter parts, i.e. RequiredBy or ConsistsOf in A.service ?


Solution 1:

Using second option (BindsTo + After) suites your use case best. BindsTo allows B to stop when A stops, B starts when A starts. B does not start when A is not yet started.