2
1
I've got two systemd timers and their associated services:
a.timer
triggeringa.service
b.timer
triggeringb.service
Both services perform housekeeping tasks using the system package manager so they must not be run in parallel (in fact, either service fails if it is started while the other is running, as both try to create a lock file).
My aim is to ensure that both services do get run so b.service
shall be delayed if a.service
is running and vice versa.
If I understand systemd.unit(5) correctly I cannot use Conflicts=
as this would actively stop one service when the other one is being started. I cannot use After=
or Before=
either (with Type=simple
) as this would delay the second service only until the first one is initialized (i.e. still running).
One solution, to my understanding, would be the combination of Type=oneshot
and After=
as oneshot makes systemd consider the unit active (and immediately dead) after the main process has terminated. On the other hand, using Type=oneshot
is explicitly discouraged for possibly long-running tasks.
One could also put both tasks in one .service
unit using
ExecStart=/usr/bin/sh -c 'first-command; second-command'
but I'd consider this very ugly as it would bind the execution interval of both services together.
So what is the most systemd'ish way of having multiple services that depend on the same exclusive resource?