Grouping systemd services

You want a target-type unit, with all the service units listed as Wants= dependencies. Then you start it using systemctl start unitname.target. (Make sure not to use systemctl isolate here; that will shut down everything except what's in your services' dependency tree, which you presumably don't want.)


Have you tried using PartOf on the sub-units of the target group in addition to Wants in the target? Ex: PartOf=foo.target in foo-sub1.service and Wants=foo-sub1.service foo-sub2.service in foo.target. I just tried this and was able to start and stop all my sub-units just by starting and stopping the target.

PartOf=

Configures dependencies similar to Requires=, but limited to stopping and restarting of units. When systemd stops or restarts the units listed here, the action is propagated to this unit. Note that this is a one-way dependency — changes to this unit do not affect the listed units.

When PartOf=b.service is used on a.service, this dependency will show as ConsistsOf=a.service in property listing of b.service. ConsistsOf= dependency cannot be specified directly.

Tags:

Systemd