github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/engine/test/utils/exec_with_retry (about)

     1  #!/bin/bash
     2  set -e
     3  set -o pipefail
     4  
     5  count=10
     6  interval_sec=1
     7  cmd=""
     8  
     9  while [[ ${1} ]]; do
    10  	case "${1}" in
    11  	--count)
    12  		count=${2}
    13  		shift
    14  		;;
    15  	--interval_sec)
    16  		interval_sec=${2}
    17  		shift
    18  		;;
    19  	*)
    20  		cmd="$cmd ${1}"
    21  		;;
    22  	esac
    23  
    24  	if ! shift; then
    25  		echo 'Missing parameter argument.' >&2
    26  		exit 1
    27  	fi
    28  done
    29  
    30  echo "will execute with retry, cmd: $cmd"
    31  i=0
    32  while ! eval $cmd; do
    33  	i=$((i + 1))
    34  	if [ "$i" -gt "$count" ]; then
    35  		echo -e "\nfailed to execute cmd for $count times: $cmd\n"
    36  		exit 2
    37  	fi
    38  	sleep $interval_sec
    39  	echo "retry $i time(s), cmd: $cmd"
    40  done