Score:0

Delay systemd timer until conflicting service has finished

lr flag

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).

Jaromanda X avatar
ru flag
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
Manuel avatar
lr flag
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.
Jaromanda X avatar
ru flag
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
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.