From e05ebe5db2bfef9201d3c46a76af2b60d03c912d Mon Sep 17 00:00:00 2001 From: Anil Belur Date: Wed, 8 Nov 2017 08:14:26 +1000 Subject: [PATCH] Ensure apt is not locked on Ubuntu nodes 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 --- packer/provision/baseline.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packer/provision/baseline.sh b/packer/provision/baseline.sh index 78e3b64a8..978296bb5 100644 --- a/packer/provision/baseline.sh +++ b/packer/provision/baseline.sh @@ -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" -- 2.36.6