catalyst-auto: add an option to hold a lock while running
This makes it easy to put into a cronjob and not worry about a copy already/still running.
This commit is contained in:
parent
fdc39e249c
commit
51b8860d23
1 changed files with 17 additions and 0 deletions
|
@ -26,6 +26,7 @@ keep_tmpdir=0
|
||||||
testing=0
|
testing=0
|
||||||
preclean=0
|
preclean=0
|
||||||
lastrun=0
|
lastrun=0
|
||||||
|
lock_file=
|
||||||
|
|
||||||
# Set pipefail so that run_cmd returns the right value in $?
|
# Set pipefail so that run_cmd returns the right value in $?
|
||||||
set -o pipefail
|
set -o pipefail
|
||||||
|
@ -48,6 +49,7 @@ Options:
|
||||||
-k|--keep-tmpdir Don't remove temp dir when build finishes
|
-k|--keep-tmpdir Don't remove temp dir when build finishes
|
||||||
-t|--test Stop after mangling specs and copying files
|
-t|--test Stop after mangling specs and copying files
|
||||||
--interval <days> Exit if last successful run was less than <days> ago
|
--interval <days> Exit if last successful run was less than <days> ago
|
||||||
|
-l|--lock <file> File to grab a lock on to prevent multiple invocations
|
||||||
-h|--help Show this message and quit
|
-h|--help Show this message and quit
|
||||||
|
|
||||||
EOH
|
EOH
|
||||||
|
@ -130,6 +132,10 @@ do
|
||||||
lastrun=$1
|
lastrun=$1
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
|
-l|--lock)
|
||||||
|
lock_file=$1
|
||||||
|
shift
|
||||||
|
;;
|
||||||
-*)
|
-*)
|
||||||
usage "ERROR: You have specified an invalid option: ${a}"
|
usage "ERROR: You have specified an invalid option: ${a}"
|
||||||
exit 1
|
exit 1
|
||||||
|
@ -137,6 +143,15 @@ do
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
(
|
||||||
|
|
||||||
|
if [[ -n ${lock_file} ]]; then
|
||||||
|
if ! flock -n 9; then
|
||||||
|
echo "catalyst-auto already running"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
# Probe the default gitdir from this script name.
|
# Probe the default gitdir from this script name.
|
||||||
GITDIR=$(dirname "$(dirname "$(realpath "$0")")")
|
GITDIR=$(dirname "$(dirname "$(realpath "$0")")")
|
||||||
|
|
||||||
|
@ -331,3 +346,5 @@ if [ ${build_failure} = 0 ]; then
|
||||||
else
|
else
|
||||||
send_email "Catalyst build complete, but with errors" "Build process has completed, but there were errors. Please consult previous emails to determine the problem."
|
send_email "Catalyst build complete, but with errors" "Build process has completed, but there were errors. Please consult previous emails to determine the problem."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
) 9>"${lock_file:-/dev/null}"
|
||||||
|
|
Loading…
Add table
Reference in a new issue