commit: 51b8860d23dd16bd51d6e87a0d13d2bb6ae27073
Author: Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Wed Mar 23 18:20:52 2016 +0000
Commit: Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Wed Mar 23 18:20:52 2016 +0000
URL: https://gitweb.gentoo.org/proj/releng.git/commit/?id=51b8860d
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.
tools/catalyst-auto | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/tools/catalyst-auto b/tools/catalyst-auto
index 0b1c389..75f6a84 100755
--- a/tools/catalyst-auto
+++ b/tools/catalyst-auto
@@ -26,6 +26,7 @@ keep_tmpdir=0
testing=0
preclean=0
lastrun=0
+lock_file=
# Set pipefail so that run_cmd returns the right value in $?
set -o pipefail
@@ -48,6 +49,7 @@ Options:
-k|--keep-tmpdir Don't remove temp dir when build finishes
-t|--test Stop after mangling specs and copying files
--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
EOH
@@ -130,6 +132,10 @@ do
lastrun=$1
shift
;;
+ -l|--lock)
+ lock_file=$1
+ shift
+ ;;
-*)
usage "ERROR: You have specified an invalid option: ${a}"
exit 1
@@ -137,6 +143,15 @@ do
esac
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.
GITDIR=$(dirname "$(dirname "$(realpath "$0")")")
@@ -331,3 +346,5 @@ if [ ${build_failure} = 0 ]; then
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."
fi
+
+) 9>"${lock_file:-/dev/null}"