Fix race condition with systemd's apt initialization

When LXC container start systemd runs apt.systemd.daily,
which locks dpkg database.

This change implements a 'wait for lock release', so that
install hook doesn't fail when deploying inside LXC.

Change-Id: I71a38ec8ea208f6c9ef1ae3dabda63bd26fa20fa
Closes-Bug: 1656651
This commit is contained in:
Mario Splivalo 2017-01-16 11:26:27 +01:00
parent f3226f8dde
commit 8e3b47678e
1 changed files with 5 additions and 0 deletions

View File

@ -4,9 +4,14 @@
declare -a DEPS=('apt' 'netaddr' 'netifaces' 'pip' 'yaml')
wait_for_dpkg_unlock() {
while $(fuser -s /var/lib/dpkg/lock); do sleep .5;done
}
check_and_install() {
pkg="${1}-${2}"
if ! dpkg -s ${pkg} 2>&1 > /dev/null; then
wait_for_dpkg_unlock
apt-get -y install ${pkg}
fi
}