github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/tests/integration_tests/_utils/run_cdc_server (about) 1 #!/bin/bash 2 3 # --workdir: work directory 4 # --tlsdir: work directory 5 # --cert-allowed-cn: cert allowed cn 6 # --binary: path to cdc test binary 7 # --logsuffix: log suffix 8 # --addr: address 9 # --pd: pd address 10 11 set -e 12 13 workdir= 14 tls= 15 tls_dir= 16 certcn= 17 certcn_name="server" 18 binary= 19 logsuffix= 20 addr= 21 addr_url="127.0.0.1:8300" 22 pd_addr= 23 pwd=$pwd 24 log_level=debug 25 restart= 26 failpoint=$GO_FAILPOINTS 27 config_path= 28 data_dir= 29 curl_status_cmd= 30 supposed_to_fail="no" 31 cluster_id="default" 32 33 while [[ ${1} ]]; do 34 case "${1}" in 35 --workdir) 36 workdir=${2} 37 shift 38 ;; 39 --tlsdir) 40 tls_dir=${2} 41 tls="--ca ${2}/ca.pem --cert ${2}/server.pem --key ${2}/server-key.pem" 42 shift 43 ;; 44 --cert-allowed-cn) 45 certcn_name=${2} 46 certcn="--cert-allowed-cn ${2}" 47 shift 48 ;; 49 --binary) 50 binary=${2} 51 shift 52 ;; 53 --logsuffix) 54 logsuffix=${2} 55 shift 56 ;; 57 --addr) 58 addr_url=${2} 59 addr="--addr ${2}" 60 shift 61 ;; 62 --pd) 63 pd_addr="--pd ${2}" 64 shift 65 ;; 66 --loglevel) 67 log_level=${2} 68 shift 69 ;; 70 --restart) 71 restart=${2} 72 shift 73 ;; 74 --failpoint) 75 failpoint=${2} 76 shift 77 ;; 78 --config) 79 config_path="--config ${2}" 80 shift 81 ;; 82 --supposed-to-fail) 83 supposed_to_fail="${2}" 84 shift 85 ;; 86 --data-dir) 87 data_dir=${2} 88 shift 89 ;; 90 --cluster-id) 91 cluster_id=${2} 92 shift 93 ;; 94 *) 95 echo "Unknown parameter: ${1}" >&2 96 exit 1 97 ;; 98 esac 99 100 if ! shift; then 101 echo 'Missing parameter argument.' >&2 102 exit 1 103 fi 104 done 105 106 if [ -z "$data_dir" ]; then 107 data_dir=${workdir}/cdc_data${logsuffix} 108 fi 109 110 echo "[$(date)] <<<<<< START cdc server in $TEST_NAME case >>>>>>" 111 cd $workdir 112 pid=$(ps -C run_cdc_server -o pid= | tr -d '[:space:]') 113 # Uncomment to turn on grpc versbose log. 114 # GRPC_GO_LOG_VERBOSITY_LEVEL=99 GRPC_GO_LOG_SEVERITY_LEVEL=debug \ 115 116 set -x 117 118 if [[ "$restart" == "true" ]]; then 119 while true; do 120 GO_FAILPOINTS=$failpoint $binary -test.coverprofile="$OUT_DIR/cov.$TEST_NAME.$pid.out" server \ 121 --log-file $workdir/cdc$logsuffix.log \ 122 --log-level $log_level \ 123 --data-dir "$data_dir" \ 124 --cluster-id "$cluster_id" \ 125 $config_path \ 126 $tls \ 127 $certcn \ 128 $addr \ 129 $pd_addr &>>$workdir/stdout$logsuffix.log 130 if [ $? -eq 143 ]; then 131 break 132 fi 133 sleep 1 134 done & 135 else 136 GO_FAILPOINTS=$failpoint $binary -test.coverprofile="$OUT_DIR/cov.$TEST_NAME.$pid.out" server \ 137 --log-file $workdir/cdc$logsuffix.log \ 138 --log-level $log_level \ 139 --data-dir "$data_dir" \ 140 --cluster-id "$cluster_id" \ 141 $config_path \ 142 $tls \ 143 $certcn \ 144 $addr \ 145 $pd_addr &>>$workdir/stdout$logsuffix.log & 146 fi 147 148 # Make sure cdc is ready to serve 149 150 # Because curl may encounter errors, 151 # it is acceptable and will retry, so you cannot quit. 152 set +e 153 154 get_info_fail_msg="failed to get info:" 155 etcd_info_msg="etcd info" 156 # If tls is set, then we need to pass the certificate and use https. 157 # Note that the certificate name may be specified. 158 if [ -z "$tls_dir" ]; then 159 curl_status_cmd="curl -vsL --max-time 20 http://$addr_url/debug/info --user ticdc:ticdc_secret -vsL" 160 else 161 curl_status_cmd="curl --cacert $tls_dir/ca.pem --cert $tls_dir/$certcn_name.pem --key $tls_dir/$certcn_name-key.pem --user ticdc:ticdc_secret -vsL --max-time 20 https://$addr_url/debug/info" 162 fi 163 164 # If the command is supposed to fail (in check usage tips test), just exit without retry 165 if [[ "$supposed_to_fail" != "no" ]]; then 166 set +x 167 exit 0 168 fi 169 170 for ((i = 0; i <= 50; i++)); do 171 res=$($curl_status_cmd) 172 # Make sure we get the capture info(etcd_info_msg) and that there are no errors(get_info_fail_msg). 173 if (! echo "$res" | grep -q "$get_info_fail_msg") && (echo "$res" | grep -q "$etcd_info_msg"); then 174 break 175 fi 176 if [ "$i" -eq 50 ]; then 177 echo 'Failed to start TiCDC' 178 exit 1 179 fi 180 sleep 3 181 done 182 183 set +x 184 185 cd $pwd