Merge pull request #1335 from ripesensor/develop

Apt wait for lock modification
This commit is contained in:
Pedro Algarvio 2019-04-05 17:36:39 +01:00 committed by GitHub
commit eb9243007b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -521,6 +521,12 @@ __exit_cleanup() {
rm -f "$LOGPIPE"
fi
# Remove the temporary apt error file when the script exits
if [ -f "$APT_ERR" ]; then
echodebug "Removing the temporary apt error file $APT_ERR"
rm -f "$APT_ERR"
fi
# Kill tee when exiting, CentOS, at least requires this
# shellcheck disable=SC2009
TEE_PID=$(ps ax | grep tee | grep "$LOGFILE" | awk '{print $1}')
@ -1813,28 +1819,27 @@ __function_defined() {
# a boot process, such as on AWS AMIs. This func will wait until the boot
# process is finished so the script doesn't exit on a locked proc.
#----------------------------------------------------------------------------------------------------------------------
APT_ERR=$(mktemp /tmp/apt_error.XXXX)
__wait_for_apt(){
# Timeout set at 15 minutes
WAIT_TIMEOUT=900
# Run our passed in apt command
"${@}"
"${@}" 2>"$APT_ERR"
APT_RETURN=$?
# If our exit code from apt is 100, then we're waiting on a lock
while [ $APT_RETURN -eq 100 ]; do
# Make sure we're not waiting on a lock
while [ $APT_RETURN -ne 0 ] && grep -q '^E: Could not get lock' "$APT_ERR"; do
echoinfo "Aware of the lock. Patiently waiting $WAIT_TIMEOUT more seconds..."
sleep 1
WAIT_TIMEOUT=$((WAIT_TIMEOUT - 1))
# If timeout reaches 0, abort.
if [ "$WAIT_TIMEOUT" -eq 0 ]; then
echoerror "Apt, apt-get, aptitude, or dpkg process is taking too long."
echoerror "Bootstrap script cannot proceed. Aborting."
return 1
else
# Try running apt again until our return code != 100
"${@}"
"${@}" 2>"$APT_ERR"
APT_RETURN=$?
fi
done