Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 26 additions & 8 deletions scripts/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
# POD_IP_TYPE = Address type of POD_IP (one of IPV4, IPv6)
# 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 @@ -138,6 +141,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 @@ -179,23 +183,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

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

for i in {900..0}; do
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
Expand Down Expand Up @@ -594,6 +607,8 @@ install_group_replication_plugin
install_clone_plugin

while true; do
log "INFO" "creating setup.txt file"
echo "running">/scripts/setup.txt
kill -0 $pid
exit="$?"
if [[ "$exit" == "0" ]]; then
Expand Down Expand Up @@ -629,6 +644,9 @@ 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