Search code examples
linuxservicesystemd

Systemd services dependency


I am trying to manage three services using systemd. The structure of the service is as follows:

enter image description here

When A target is started/stopped/enabled, this should be propagated to the other services (A0, A1, A2).

However, it should still be possible to start/stop/enable A0-A2 independently from each other and A.

So far A.target looks similar to this:

[Unit]
DefaultDependencies=no
Wants=A0.service
Wants=A1.service
Wants=A2.service

[Install]
WantedBy=multi-user.target
Also=A0.service
Also=A1.service
Also=A2.service

A0.service:

[Unit]
Requires=some-other.service
After=some-other.service
BindsTo=A.target
DefaultDependencies=no

[Install]
WantedBy=multi-user.target

Starting/stopping works fine, however when I start a single service (eg. A0) all the other services are started as well. Why is that and what is a proper way to fix this?


Solution

  • Seems like the combination between "Wants" within A.target and "BindsTo" within A0.service led to the problem. Changing "BindsTo" to "PartOf" fixed the problem.