Modify your database setup process to drop a canary file into
/var/run (e. g.
/var/run/db_freeze) upon startup, and remove it upon completion.
cron jobs to immediately terminate upon startup if that file exists.
For example, for the long-running job:
# long-running DB setup job
trap 'rm -f /var/run/db_freeze' EXIT
And for the
if [[ -f /var/run/db_freeze ]]; then
# Bail due to process lock from long-running job
If you want to wait for the longer process to finish, and then kick it off, rather than
exiting, you can wait for the canary to go away:
while [[ -f /var/run/db_freeze ]]; do
Note, however, that without working on locking the cron jobs themselves, if the long process goes longer than one
cron cycle, you could end up with two concurrent instances of the
cron job waiting to jump into action.