Last active
January 29, 2020 19:29
-
-
Save sshymko/0f2e1c6251fa69584d94c43e549f164b to your computer and use it in GitHub Desktop.
Wrapper launching single process using its execution permission as concurrency semaphore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
if [ -z "$1" ]; then | |
echo "Usage: $0 <command> [args...]" | |
exit | |
fi | |
trap ':' SIGINT SIGTERM | |
chmod u-x "$0" | |
"$@" | |
status=$? | |
chmod u+x "$0" | |
exit $status |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Protect cron from launching new jobs until the previous one has finished:
Even though the job is scheduled to run every 10 min, it will be executed every 20 min, because it takes 15 min (900 sec) to complete and every other launch attempt will fail with the
Permission denied
error protecting from undesirable concurrency.Note: Every job needs its own copy of
only.sh
as the script's execution permission bit is used as a semaphore; symlink won't work.