Skip to content
30 changes: 22 additions & 8 deletions scripts/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# PRIMARY_TYPE = defines single/multi primary

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
Expand Down Expand Up @@ -136,6 +137,7 @@ log_bin = binlog
loose-group_replication_bootstrap_group = OFF
loose-group_replication_start_on_boot = OFF
loose_group_replication_unreachable_majority_timeout = 20
loose_group_replication_exit_state_action = OFFLINE_MODE

# default tls configuration for the group
# group_replication_recovery_use_ssl will be overwritten from DB arguments
Expand Down Expand Up @@ -177,24 +179,32 @@ fi
# 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
# process (e.g. KubeDB health checker) from writing local GTIDs before
Expand Down Expand Up @@ -595,6 +605,8 @@ install_group_replication_plugin
install_clone_plugin

while true; do
echo "running">/scripts/setup.txt
log "INFO" "creating setup.txt file"
kill -0 $pid
exit="$?"
if [[ "$exit" == "0" ]]; then
Expand Down Expand Up @@ -630,6 +642,8 @@ while true; do
join_by_clone
fi
joining_for_first_time=0
log "INFO" "removing setup.txt file"
rm -rf /scripts/setup.txt
log "INFO" "waiting for mysql process id = $pid"
wait $pid
done
Loading