Module: check_mk
Branch: master
Commit: 71ffc7ec41affcc0315792a4363c091a696c4e5d
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=71ffc7ec41affc…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Tue Oct 24 11:08:45 2017 +0200
make-agent: Lock chroot setup / up-to-date check for build environment
Change-Id: Ia49f8fcb67fa632cd85fba56af00daed7306c5e4
---
agents/windows/make-agent | 47 +++++++++++++++++++++++++++++------------------
1 file changed, 29 insertions(+), 18 deletions(-)
diff --git a/agents/windows/make-agent b/agents/windows/make-agent
index 619f0c3..1623201 100755
--- a/agents/windows/make-agent
+++ b/agents/windows/make-agent
@@ -35,25 +35,36 @@ if [ ! -f "$base/agents/windows/$versionfile" ] ; then
exit 1
fi
-# Ensure that chroot exists and is up to date:
-# ensure that versionfile exists...
-if [ ! -f "$CHROOT_PATH/$versionfile" ] ; then
- echo "chroot version not found."
- create=yes
- # ... and it is up to date.
-elif [ $(cat "$CHROOT_PATH/$versionfile") -ne \
- $(cat "$base/agents/windows/$versionfile") ] ; then
- echo "chroot is out of date."
- create=yes
-fi
+# Realize a file based locking for the chroot setup. There must be only
+# a single caller executing the setup of a chroot. Once the chroot was
+# created, multiple jobs may be executed in the chroot simultaneously,
+# but the setup must be performed only by a single job.
+(
+ echo "[MAKE-CHROOT LOCK] aquire"
+ flock -x -w 1800 200 || (echo "[MAKE-CHROOT LOCK] ERROR: Failed to get lock
within 1800 seconds" ; exit 1)
+ echo "[MAKE-CHROOT LOCK] got it"
-if [ -z $create ] ; then
- echo "chroot is up to date."
-else
- apt-get -y install "${chroot_dependencies[@]}"
- VERSIONFILE=$versionfile CHROOT_PATH=$CHROOT_PATH \
- CHROOT_BUILD_DIR=$CHROOT_BUILD_DIR ./make-chroot
-fi
+ # Ensure that chroot exists and is up to date:
+ # ensure that versionfile exists...
+ if [ ! -f "$CHROOT_PATH/$versionfile" ] ; then
+ echo "chroot version not found."
+ create=yes
+ # ... and it is up to date.
+ elif [ $(cat "$CHROOT_PATH/$versionfile") -ne \
+ $(cat "$base/agents/windows/$versionfile") ] ; then
+ echo "chroot is out of date."
+ create=yes
+ fi
+
+ if [ -z $create ] ; then
+ echo "chroot is up to date."
+ else
+ apt-get -y install "${chroot_dependencies[@]}"
+ VERSIONFILE=$versionfile CHROOT_PATH=$CHROOT_PATH \
+ CHROOT_BUILD_DIR=$CHROOT_BUILD_DIR ./make-chroot
+ fi
+) 200>/var/lock/cmk-make-agent_${CHROOT_PATH//\//-}.lock
+echo "[MAKE-CHROOT LOCK] released"
# Build the Windows agent within chroot by calling the 'build-agent' script as
# $SUDO_USER.