6

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

  • 1
    Why not just have A requires B, B requires C and check for A during application initialisation ? – Iain Aug 14 '15 at 7:51
  • 1
    I do just that, but that does not solve the problem I described above. If A, B or C stops or crashes I want my group service to be flagged as "inactive", – Kimble Aug 14 '15 at 14:26
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.