diff --git a/scripts/run.sh b/scripts/run.sh index 4d14e9e..41c770c 100755 --- a/scripts/run.sh +++ b/scripts/run.sh @@ -17,6 +17,7 @@ # POD_IP_TYPE = Address type of POD_IP (one of IPV4, IPv6) env | sort | grep "POD\|HOST\|NAME" +echo "running">/scripts/setup.txt RECOVERY_DONE_FILE="/tmp/recovery.done" if [[ "$PITR_RESTORE" == "true" ]]; then while true; do @@ -173,23 +174,31 @@ EOL # wait for mysql daemon be running (alive) function wait_for_mysqld_running() { local mysql="$mysql_header --host=$localhost" + local max_restarts=60 + local restarts=0 - for i in {900..0}; do + while true; do + if ! kill -0 "$pid" 2>/dev/null; then + if (( restarts >= max_restarts )); then + log "ERROR" "mysqld (pid=$pid) died and exceeded $max_restarts restart attempts. Aborting." + exit 1 + fi + restarts=$((restarts + 1)) + log "ERROR" "mysqld (pid=$pid) is no longer running. Restart attempt $restarts/$max_restarts..." + start_mysqld_in_background + sleep 10 + continue + fi out=$(${mysql} -N -e "select 1;" 2>/dev/null) log "INFO" "Attempt $i: Pinging '$report_host' has returned: '$out'...................................." if [[ "$out" == "1" ]]; then + log "INFO" "mysqld is ready (pid=$pid, restarts=$restarts)" break fi - + log "INFO" "Pinging '$report_host' has returned: '$out' (pid=$pid alive, restarts=$restarts)" echo -n . sleep 1 done - - if [[ "$i" == "0" ]]; then - echo "" - log "ERROR" "Server ${report_host} failed to start in 900 seconds............." - exit 1 - fi log "INFO" "mysql daemon is ready to use......." # Set read-only immediately after MySQL starts to prevent any external @@ -404,6 +413,8 @@ create_replication_user install_group_replication_plugin while true; do + echo "running">/scripts/setup.txt + log "INFO" "creating setup.txt file" kill -0 $pid exit="$?" if [[ "$exit" == "0" ]]; then @@ -431,6 +442,8 @@ while true; do wait_for_primary "${member_hosts[*]}" join_into_cluster fi - echo $pid + log "INFO" "removing setup.txt file" + rm -rf /scripts/setup.txt + log "INFO" "waiting for mysql process id = $pid" wait $pid done