retry-tool.sh 416 B

1234567891011121314151617
  1. #!/bin/bash
  2. set -xe -o pipefail
  3. RETRY_COUNTER=0
  4. MAX_RETRY=10
  5. CUR_TIMEOUT=120
  6. while [[ $RETRY_COUNTER -lt $MAX_RETRY ]]; do
  7. (timeout $CUR_TIMEOUT "$@") && break || sleep $(shuf -i 5-90 -n 1)
  8. RETRY_COUNTER=$(( $RETRY_COUNTER + 1 ))
  9. CUR_TIMEOUT=$(( $CUR_TIMEOUT + 60 ))
  10. echo "Retry $RETRY_COUNTER..."
  11. done
  12. if [[ $RETRY_COUNTER -ge $MAX_RETRY ]]; then
  13. echo "Max retry count exceeded."
  14. exit 1
  15. fi