From 4b79476969def3e3510f3859e1539386b5b0d471 Mon Sep 17 00:00:00 2001 From: Markos Chandras Date: Wed, 27 Sep 2017 16:46:07 +0100 Subject: xci: scripts: start-new-vm.sh: Do not allow multiple build-dib-os processes apt-get is really unhappy when another instance is running and fails with the following error: E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable) E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it? Change-Id: I2fe343fdab8438cb112cce0a4f81c7e3977c55f9 Signed-off-by: Markos Chandras --- xci/scripts/vm/build-dib-os.sh | 2 +- xci/scripts/vm/start-new-vm.sh | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) (limited to 'xci') diff --git a/xci/scripts/vm/build-dib-os.sh b/xci/scripts/vm/build-dib-os.sh index 78eaff2d..2f788006 100755 --- a/xci/scripts/vm/build-dib-os.sh +++ b/xci/scripts/vm/build-dib-os.sh @@ -7,7 +7,7 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## -set -e +set -ex # This only works on ubuntu hosts lsb_release -i | grep -q -i ubuntu || { echo "This script only works on Ubuntu distros"; exit 1; } diff --git a/xci/scripts/vm/start-new-vm.sh b/xci/scripts/vm/start-new-vm.sh index c374071c..991637a6 100755 --- a/xci/scripts/vm/start-new-vm.sh +++ b/xci/scripts/vm/start-new-vm.sh @@ -8,7 +8,7 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## -set -e +set -ex lsb_release -i | grep -q -i ubuntu || { echo "This script only works on Ubuntu distros"; exit 1; } @@ -38,8 +38,18 @@ declare -r BASE_PATH=$(dirname $(readlink -f $0) | sed "s@/xci/.*@@") echo "Preparing new virtual machine '${NAME}'..." # NOTE(hwoarang) This should be removed when we move the dib images to a central place +_retries=20 echo "Building '${OS}' image (tail build.log for progress and failures)..." -$BASE_PATH/xci/scripts/vm/build-dib-os.sh ${OS} > build.log 2>&1 +while [[ $_retries -ne 0 ]]; do + if pgrep build-dib-os.sh &>/dev/null; then + echo "There is another dib process running... ($_retries retries left)" + sleep 60 + (( _retries = _retries - 1 )) + else + $BASE_PATH/xci/scripts/vm/build-dib-os.sh ${OS} > build.log 2>&1 + break + fi +done [[ ! -e ${OS}.qcow2 ]] && echo "${OS}.qcow2 not found! This should never happen!" && exit 1 -- cgit 1.2.3-korg