I want to use systemd to run a command every 5 minutes. However, there is a risk that occasionally the task may take longer than 5 minutes to run. At that point, will systemd start a second instance of the command i.e. will I end up with 2 processes running?
Is it possible to tell systemd not to start a second process if the first hasn't completed? If not, what are some good workarounds?
Note: I hope the answer is "That's the default behavior. It just isn't documented." If this is the situation, can someone tell me how to file a bug against their docs?
Note: Cron has a similar issue which is discussed in https://unix.stackexchange.com/a/173928/11244. I'm looking for the systemd equivalent.
Best Answer
This is the default (and the only) behavior. It is not explicitly documented, but is implied by systemd's operation logic.
systemd.timer(5) reads:
systemd(1), in turn, describes the concept of unit states and transitions between them:
This means that the triggering of a timer leads to "activation" of the matching unit, i. e. its transition to the "active" state.
If the matching unit is already "active" at the time of "activation" (for a service unit, this means "the main process is still running", unless the service unit has
Type=oneshot
andRemainAfterExit=true
), it should be obvious that no action will be taken.