10

I have two services A and B which run continuously, for them I use systemd service units. At specific times service C should be run, I can do this using a timer and a service with the same name. C finishes after a short time. When C runs, A and B should not run. To ensure this, I use in the service file for C the Conflicts= option, which is explained on this webpage: systemd documentation. But this options only stops A and B. How can I start A and B again, when C finishes? Can I do this using systemd?

Note: To call systemctl start A.service and systemctl start B.service is not the kind of solution I am looking for.

1
  • 1
    I guess it's a dirty way to do that... can you trigger A and B in ExecStop of C?
    – Thushi
    Mar 1, 2016 at 13:49

1 Answer 1

7

I would recommend using:

ExecStopPost=/usr/bin/systemctl start A.service B.service

Additional commands that are executed after the service is stopped

Using ExecStopPost instead of ExecStop is important because when ExecStop is run the service is still considered up, so the conflict will still apply.

3
  • Thanks for your answer, I will use your first suggestion. I think there is a misunderstanding, I have no objections to your first suggestion. Jul 1, 2017 at 15:07
  • my complaint with this solution is that it requires editing the C unit file. I would like to see a solution that only requires editing the A and/or B unit files.
    – gam3
    Oct 5, 2020 at 19:14
  • 1
    @gam3 I would disagree - C.service is the one with special requirements, so it should be responsible for making its requirements true. Editing A and B is more impact (editing two services instead of one) so that they can do the work that C requires for it.
    – Centimane
    Oct 10, 2020 at 16:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .