]> git.ipfire.org Git - people/ms/nightly-builds.git/commitdiff
Make sure this script can only run once at a time
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 28 Sep 2015 19:00:23 +0000 (21:00 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 28 Sep 2015 19:00:23 +0000 (21:00 +0200)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
build.sh

index afed95ca5ef903ec8ebffb4e854f8b52f7ef6509..a8060454f585f70318af1284b5f5712c6e3a0d64 100755 (executable)
--- a/build.sh
+++ b/build.sh
@@ -1,6 +1,7 @@
 #!/bin/bash -l
 
 BASEDIR="/build/nightly"
+LOCKFILE="/tmp/.nightly-builds.lock"
 
 UPLOAD_DIR="${BASEDIR}/upload"
 UPLOAD_TO="pakfire@git.ipfire.org:/pub/nightly"
@@ -99,8 +100,32 @@ sync() {
                "${UPLOAD_DIR}/" "${UPLOAD_TO}"
 }
 
+is_locked() {
+       [ -e "${LOCKFILE}" ]
+}
+
+lock() {
+       touch "${LOCKFILE}"
+}
+
+unlock() {
+       rm -f "${LOCKFILE}"
+}
+
+
+# Don't start again if the script is already running
+if is_locked; then
+       exit 0
+fi
+
+# Lock
+trap unlock EXIT
+lock
+
 for repo in $(find ${BASEDIR} -maxdepth 2 -type d -name ".git"); do
        [ -d "${repo}" ] || continue
 
        build "$(dirname ${repo})"
 done
+
+exit 0