Fixes multiple issues with retry function in rhel-registration.
There were multiple issues in retry() in rhel-registration: - There was no need for it to be recursive (local variables got overwritten) - There was no delay between multiple attempts, leading to faster but more frequent failures. - The max number of attempts was set too low for some environements. With this patch, rhel-registration now works more reliably with slow-links for portal registration and does not attempt to DDos the portal or your satellite server. Change-Id: I594d3c94867b45a7a58766dbcc66edead78d6a4e
This commit is contained in:
parent
a681b98564
commit
038eae0891
@ -11,7 +11,7 @@ if [ -e $OK ] ; then
|
|||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
retryCount=0
|
retry_max_count=10
|
||||||
opts=
|
opts=
|
||||||
config_opts=
|
config_opts=
|
||||||
attach_opts=
|
attach_opts=
|
||||||
@ -157,27 +157,41 @@ else
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
function retry() {
|
function retry() {
|
||||||
if [[ $retryCount < 3 ]]; then
|
# Inhibit -e since we want to retry without exiting..
|
||||||
$@
|
set +e
|
||||||
if ! [[ $? == 0 ]]; then
|
# Retry delay (seconds)
|
||||||
retryCount=$(echo $retryCount + 1 | bc)
|
retry_delay=2.0
|
||||||
echo "WARN: Failed to connect when running '$@', retrying..."
|
retry_count=0
|
||||||
retry $@
|
mycli="$@"
|
||||||
else
|
while [ $retry_count -lt ${retry_max_count} ]
|
||||||
retryCount=0
|
do
|
||||||
|
echo "INFO: Sleeping ${retry_delay} ..."
|
||||||
|
sleep ${retry_delay}
|
||||||
|
echo "INFO: Executing '${mycli}' ..."
|
||||||
|
${mycli}
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
echo "INFO: Ran '${mycli}' successfully, not retrying..."
|
||||||
|
break
|
||||||
|
else
|
||||||
|
echo "WARN: Failed to connect when running '${mycli}', retrying (attempt #$retry_count )..."
|
||||||
|
retry_count=$(echo $retry_count + 1 | bc)
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ $retry_count -ge ${retry_max_count} ]; then
|
||||||
|
echo "ERROR: Failed to connect after ${retry_max_count} attempts when running '${mycli}'"
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
else
|
# Re-enable -e when exiting retry()
|
||||||
echo "ERROR: Failed to connect after 3 attempts when running '$@'"
|
set -e
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function detect_satellite_version {
|
function detect_satellite_version {
|
||||||
ping_api=$REG_SAT_URL/katello/api/ping
|
ping_api=$REG_SAT_URL/katello/api/ping
|
||||||
if curl --retry 3 --retry-delay 10 --max-time 30 -L -k -s -D - -o /dev/null $ping_api | grep "200 OK"; then
|
if curl --retry ${retry_max_count} --retry-delay 10 --max-time 30 -L -k -s -D - -o /dev/null $ping_api | grep "200 OK"; then
|
||||||
echo Satellite 6 detected at $REG_SAT_URL
|
echo Satellite 6 detected at $REG_SAT_URL
|
||||||
satellite_version=6
|
satellite_version=6
|
||||||
elif curl --retry 3 --retry-delay 10 --max-time 30 -L -k -s -D - -o /dev/null $REG_SAT_URL/rhn/Login.do | grep "200 OK"; then
|
elif curl --retry ${retry_max_count} --retry-delay 10 --max-time 30 -L -k -s -D - -o /dev/null $REG_SAT_URL/rhn/Login.do | grep "200 OK"; then
|
||||||
echo Satellite 5 detected at $REG_SAT_URL
|
echo Satellite 5 detected at $REG_SAT_URL
|
||||||
satellite_version=5
|
satellite_version=5
|
||||||
else
|
else
|
||||||
@ -220,7 +234,7 @@ case "${REG_METHOD:-}" in
|
|||||||
detect_satellite_version
|
detect_satellite_version
|
||||||
if [ "$satellite_version" = "6" ]; then
|
if [ "$satellite_version" = "6" ]; then
|
||||||
repos="$repos --enable ${satellite_repo}"
|
repos="$repos --enable ${satellite_repo}"
|
||||||
curl --retry 3 --retry-delay 10 --max-time 30 -L -k -O "$REG_SAT_URL/pub/katello-ca-consumer-latest.noarch.rpm"
|
curl --retry ${retry_max_count} --retry-delay 10 --max-time 30 -L -k -O "$REG_SAT_URL/pub/katello-ca-consumer-latest.noarch.rpm"
|
||||||
rpm -Uvh katello-ca-consumer-latest.noarch.rpm || true
|
rpm -Uvh katello-ca-consumer-latest.noarch.rpm || true
|
||||||
retry subscription-manager register $opts
|
retry subscription-manager register $opts
|
||||||
retry subscription-manager $repos
|
retry subscription-manager $repos
|
||||||
@ -229,7 +243,7 @@ case "${REG_METHOD:-}" in
|
|||||||
retry subscription-manager repos --disable ${satellite_repo}
|
retry subscription-manager repos --disable ${satellite_repo}
|
||||||
else
|
else
|
||||||
pushd /usr/share/rhn/
|
pushd /usr/share/rhn/
|
||||||
curl --retry 3 --retry-delay 10 --max-time 30 -k -O $REG_SAT_URL/pub/RHN-ORG-TRUSTED-SSL-CERT
|
curl --retry ${retry_max_count} --retry-delay 10 --max-time 30 -k -O $REG_SAT_URL/pub/RHN-ORG-TRUSTED-SSL-CERT
|
||||||
popd
|
popd
|
||||||
retry rhnreg_ks --serverUrl=$REG_SAT_URL/XMLRPC $sat5_opts
|
retry rhnreg_ks --serverUrl=$REG_SAT_URL/XMLRPC $sat5_opts
|
||||||
fi
|
fi
|
||||||
|
Loading…
Reference in New Issue
Block a user