xci: scripts: start-new-vm.sh: Do not allow multiple build-dib-os processes 51/43351/7
authorMarkos Chandras <mchandras@suse.de>
Wed, 27 Sep 2017 15:46:07 +0000 (16:46 +0100)
committerMarkos Chandras <mchandras@suse.de>
Wed, 27 Sep 2017 22:11:14 +0000 (23:11 +0100)
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 <mchandras@suse.de>
xci/scripts/vm/build-dib-os.sh
xci/scripts/vm/start-new-vm.sh

index 78eaff2..2f78800 100755 (executable)
@@ -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; }
index c374071..991637a 100755 (executable)
@@ -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