Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

Commit

Permalink
apt lock hygiene
Browse files Browse the repository at this point in the history
- only invoke an apt command if nothing else is holding a lock
- only return after an apt command after locks are verified released
  • Loading branch information
jackfrancis committed Oct 19, 2018
1 parent 38010ba commit aad8115
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 11 additions & 1 deletion parts/k8s/kubernetesprovisionsource.sh
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,17 @@ wait_for_file() {
fi
done
}
wait_for_apt_locks() {
while fuser /var/lib/dpkg/lock /var/lib/apt/lists/lock /var/cache/apt/archives/lock >/dev/null 2>&1; do
echo 'Waiting for release of apt locks'
sleep 3
done
}
apt_get_update() {
retries=10
apt_update_output=/tmp/apt-get-update.out
for i in $(seq 1 $retries); do
wait_for_apt_locks
timeout 30 dpkg --configure -a
timeout 30 apt-get -f -y install
timeout 120 apt-get update 2>&1 | tee $apt_update_output | grep -E "^([WE]:.*)|([eE]rr.*)$"
Expand All @@ -135,10 +142,12 @@ apt_get_update() {
fi
done
echo Executed apt-get update $i times
wait_for_apt_locks
}
apt_get_install() {
retries=$1; wait_sleep=$2; timeout=$3; shift && shift && shift
for i in $(seq 1 $retries); do
wait_for_apt_locks
timeout 30 dpkg --configure -a
timeout $timeout apt-get install --no-install-recommends -y ${@}
[ $? -eq 0 ] && break || \
Expand All @@ -150,6 +159,7 @@ apt_get_install() {
fi
done
echo Executed apt-get install --no-install-recommends -y \"$@\" $i times;
wait_for_apt_locks
}
systemctl_restart() {
retries=$1; wait_sleep=$2; timeout=$3 svcname=$4
Expand All @@ -163,4 +173,4 @@ systemctl_restart() {
sleep $wait_sleep
fi
done
}
}
2 changes: 2 additions & 0 deletions parts/k8s/setup-custom-search-domains.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ source /opt/azure/containers/provision_source.sh

sudo echo " dns-search <searchDomainName>" >> /etc/network/interfaces.d/50-cloud-init.cfg
systemctl_restart 20 5 10 restart networking
wait_for_apt_locks
retrycmd_if_failure 10 5 120 apt-get -y install realmd sssd sssd-tools samba-common samba samba-common python2.7 samba-libs packagekit
wait_for_apt_locks
echo "<searchDomainRealmPassword>" | realm join -U <searchDomainRealmUser>@`echo "<searchDomainName>" | tr /a-z/ /A-Z/` `echo "<searchDomainName>" | tr /a-z/ /A-Z/`

0 comments on commit aad8115

Please sign in to comment.