Ensure apt is not locked on Ubuntu nodes 88/65288/1
authorAnil Belur <abelur@linuxfoundation.org>
Tue, 7 Nov 2017 22:14:26 +0000 (08:14 +1000)
committerAnil Belur <abelur@linuxfoundation.org>
Tue, 7 Nov 2017 22:19:23 +0000 (08:19 +1000)
A background apt process locks /var/lib/dpkg/lock and causes apt
commands to fail. Therefore check if apt is locked before running
apt.

Errors:
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

Change-Id: I3ced3711b26ebe9ecf5654c70d23f44e905c1f4c
Signed-off-by: Anil Belur <abelur@linuxfoundation.org>
packer/provision/baseline.sh

index 78e3b64a87c1a3c3edeb0fd4aeaa86c8be385fa4..978296bb577415ebdce3b32e4e0414dd720577d4 100644 (file)
@@ -79,6 +79,10 @@ ensure_ubuntu_install() {
         # Retry installing package 5 times if necessary
         for i in {0..5}
         do
+
+            # Wait for any background apt processes to finish before running apt
+            while pgrep apt > /dev/null; do sleep 1; done
+
             echo "$i: Installing $pkg"
             if [ "$(dpkg-query -W -f='${Status}' "$pkg" 2>/dev/null | grep -c "ok installed")" -eq 0 ]; then
                 apt-cache policy "$pkg"