mirror of
https://github.com/saltstack/salt-bootstrap.git
synced 2025-04-16 09:40:21 +00:00
Merge pull request #1335 from ripesensor/develop
Apt wait for lock modification
This commit is contained in:
commit
eb9243007b
1 changed files with 11 additions and 6 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue