-
-
Save txominpelu/a8e886cf55e2c26d55c8 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env bash | |
set -o nounset | |
set -o errexit | |
set -o pipefail | |
declare -r max=2 | |
declare i=0 | |
function wrap() { | |
local cmd=$1 ; shift | |
retry $cmd "$@" | |
local success=$? | |
set -o errexit | |
exit $success | |
} | |
function retry() { | |
set +o errexit | |
local cmd=$1 ; shift | |
$cmd "$@" | |
s=$? | |
if [ $s -ne 0 -a $i -lt $max ] ; | |
then | |
i=$(($i+1)) | |
echo "Retrying" | |
sleep $((1+$i*$i*5)) | |
retry $cmd "$@"; | |
else | |
return $s | |
fi | |
} | |
wrap "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment