0

I have multiple jobs that should be launched periodically by a systemd timer. The jobs are mutually exclusive - if one job was to be run while another one is still running, one of the jobs might produce invalid results or even crash. Because of this I need to ensure only one of the jobs can run at a time, so if a job is already running, systemd needs to delay scheduling of any conflicting jobs until the running job has concluded.

How can I signal to sytstemd to delay a job until any conflicting jobs have concluded? Using conflicts doesn't seem like a good option to me since I want to allow already running jobs to finish on their own instead of being stopped forcefully (all of these jobs conclude eventually by themselves).

Manuel
  • 1
  • using google "systemd start task after another task finishes" yielded [this](https://askubuntu.com/questions/1072165/systemd-how-to-start-service-b-after-service-a-runs-to-completion) as the first result, which seems to indicate `Type=oneshot` may be what you need, however, I'm not sure how that *plays* with systemd timer jobs – Jaromanda X Apr 12 '23 at 02:25
  • Unfortunately this doesn't quite map to my needs. One service may for example run every ten minutes, while another task may only run every hour. As far as I understand, `after` implies that the specified service *always* runs after the service concludes, which conflicts with the heterogeneous periodicity of the tasks. – Manuel Apr 12 '23 at 07:52
  • ahh, I misunderstood, I thought things always ran in a sequence. Only other thing i can think of is to use some sort of simple locking mechanism so that only one of those processes can run at a time. if the lock isn't available, sleep then retry - or, some sort of queuing mechanism – Jaromanda X Apr 12 '23 at 08:08

0 Answers0