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:
cschantz
2026-02-10 23:46:14 -05:00
parent 569f9947fd
commit d5870de836
+30 -1
View File
@@ -878,8 +878,22 @@ start_second_instance() {
# Check if socket already exists (instance already running) # Check if socket already exists (instance already running)
if [ -S "$datadir/socket.mysql" ]; then if [ -S "$datadir/socket.mysql" ]; then
print_warning "Socket file already exists. Attempting to shut down existing instance..." 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 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 fi
# Build mysqld command # Build mysqld command
@@ -924,7 +938,22 @@ start_second_instance() {
print_error "InnoDB initialization encountered errors" print_error "InnoDB initialization encountered errors"
echo "" echo ""
print_warning "Attempting to shut down second instance..." 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 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 "" echo ""
print_info "Review full error log:" print_info "Review full error log:"
echo " tail -100 $datadir/mysql.err" echo " tail -100 $datadir/mysql.err"