How to group / compose systemd services?
I have three systemd services (Docker containers, but that is not important). All three of these services has to be running for the application to be fully functional.
In order to simplify procedures for the ops team I've created a forth systemd service to group them all together using the Requires
and PartOf
directives. Starting and stopping this forth service will now start and stop the three containers in the correct order.
The last challenge is to get the forth systemd service to show the correct status. Right now it shows "loaded / inactive" after booting up the services. Is it possible to configure it in a way that it will show "loaded / active" when and only when the three first services are up and running?
[Unit]
Description=This is the group
Requires=a.service b.service c.service
[Service]
ExecStart=/bin/echo "Starting"
ExecStop=/bin/echo "Stopping"
[Install]
WantedBy=local.target
The a.service
, b.service
and c.service
contains PartOf=group.service
Solution 1:
I think you need to add an After=
clause.
If your three services are linked, you might also be able to simplify your Requires
.
If you also wanted this fourth service to stop when the other 3 do, you would also need to add a BindsTo
entry.
As in:
[Unit]
Description=This is the group
Requires=c.service
After=c.service
BindsTo=c.service