Last active
August 29, 2015 13:58
-
-
Save cloudnull/10437603 to your computer and use it in GitHub Desktop.
BASH Successerator. when running a process that has a high probability of failure use this function as a means to ensure the operation is run multiple times.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# BASH Successerator. when running a process that has a high | |
# probability of failure use this function as a means to | |
# ensure the operation is run multiple times. | |
# Usage: | |
# successerator knife bootstrap -e ENV -r 'role[one],recipie[two]' | |
# Used to retry process that may fail due to random issues. | |
function successerator() { | |
MAX_RETRIES=${MAX_RETRIES:-5} | |
RETRY=0 | |
# Set the initial return value to failure | |
false | |
while [ $? -ne 0 -a ${RETRY} -lt ${MAX_RETRIES} ];do | |
RETRY=$((${RETRY}+1)) | |
$@ | |
done | |
if [ ${RETRY} -eq ${MAX_RETRIES} ];then | |
echo "Hit maximum number of retries, giving up..." | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment