#!/usr/bin/env bash

if [ $# -lt 2 ]; then
	echo "Usage: check_tidb_health <tidb_host> <tidb_port> <check_count>"
	exit 1
fi

host=$1
port=$2
check_count=${3:-60}
i=0
while ! mysql -uroot -h "$host" -P "$port" --default-character-set utf8mb4 -e 'select * from mysql.tidb;'; do
	i=$((i + 1))
	if [ "$i" -gt "$check_count" ]; then
		echo 'Failed to start TiDB'
		exit 2
	fi
	sleep 2
done
