Minutely cron, ensuring only a single instance

Posted by Christopher Nadeau on Server Fault See other posts from Server Fault or by Christopher Nadeau
Published on 2010-04-06T16:12:29Z Indexed on 2010/04/06 16:23 UTC
Read the original article Hit count: 282

Filed under:
|

Is there a way to run a script every minute (or 2, or 5, etc), but only if it isn't already running?

We have a set of scripts that need to run every minute. Sometimes they might start and finish in a second, other times they might go on for 5 minutes.

Our current way of avoiding simultaneous executions is by setting a is_running flag in each script, and exiting if it's still enabled. But this is a little unreliable (i.e., fatal errors would cause the flag to remain enabled even after the script halted).

We could write our own little manager, but I'm wondering if there is a more fashionable solution that already exists.

© Server Fault or respective owner

Related posts about linux

Related posts about cron