Fix missing shutdown validation in start_second_instance()
- Apply proper shutdown validation to pre-startup cleanup (line 881-899) If a stale socket exists, wait for it to be removed instead of just sleeping 2 seconds. Uses same pattern as stop_second_instance(). - Apply proper shutdown validation to error path (line 937-960) When InnoDB errors are detected, use validated shutdown with socket removal verification instead of fire-and-forget mysqladmin call. - All 4 shutdown paths now consistently: 1. Send graceful shutdown 2. Wait for socket file to disappear 3. Clean up stale socket/lock files 4. Verify process termination This ensures no stale processes/sockets remain that could cause crashes on subsequent script runs. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -878,8 +878,22 @@ start_second_instance() {
|
||||
# Check if socket already exists (instance already running)
|
||||
if [ -S "$datadir/socket.mysql" ]; then
|
||||
print_warning "Socket file already exists. Attempting to shut down existing instance..."
|
||||
|
||||
# Use proper shutdown validation (same as stop_second_instance)
|
||||
mysqladmin -h localhost -S "$datadir/socket.mysql" shutdown 2>/dev/null || true
|
||||
sleep 2
|
||||
|
||||
# Wait for socket to disappear (up to 5 seconds)
|
||||
local cleanup_wait=0
|
||||
while [ -S "$datadir/socket.mysql" ] && [ "$cleanup_wait" -lt 5 ]; do
|
||||
sleep 1
|
||||
cleanup_wait=$((cleanup_wait + 1))
|
||||
done
|
||||
|
||||
# If socket still exists, try force removal
|
||||
if [ -S "$datadir/socket.mysql" ]; then
|
||||
print_warning "Existing instance didn't shut down cleanly. Force removing socket..."
|
||||
rm -f "$datadir/socket.mysql" "$datadir/mysql.lock" 2>/dev/null || true
|
||||
fi
|
||||
fi
|
||||
|
||||
# Build mysqld command
|
||||
@@ -924,7 +938,22 @@ start_second_instance() {
|
||||
print_error "InnoDB initialization encountered errors"
|
||||
echo ""
|
||||
print_warning "Attempting to shut down second instance..."
|
||||
|
||||
# Use proper shutdown validation instead of fire-and-forget
|
||||
mysqladmin -h localhost -S "$datadir/socket.mysql" shutdown 2>/dev/null || true
|
||||
|
||||
# Wait for socket to disappear (up to 5 seconds)
|
||||
local error_cleanup_wait=0
|
||||
while [ -S "$datadir/socket.mysql" ] && [ "$error_cleanup_wait" -lt 5 ]; do
|
||||
sleep 1
|
||||
error_cleanup_wait=$((error_cleanup_wait + 1))
|
||||
done
|
||||
|
||||
# Remove stale socket/lock if still present
|
||||
if [ -S "$datadir/socket.mysql" ]; then
|
||||
rm -f "$datadir/socket.mysql" "$datadir/mysql.lock" 2>/dev/null || true
|
||||
fi
|
||||
|
||||
echo ""
|
||||
print_info "Review full error log:"
|
||||
echo " tail -100 $datadir/mysql.err"
|
||||
|
||||
Reference in New Issue
Block a user