@@ -465,24 +465,29 @@ EOF
465
465
# Stop PostgreSQL service
466
466
if [ -z " $IS_CI " ]; then
467
467
echo " Stopping PostgreSQL service..."
468
-
469
- # Disable service first so it doesn't restart automatically
470
- systemctl disable postgresql
471
-
472
- # Use systemctl stop with a longer timeout
473
- if ! systemctl stop postgresql; then
474
- echo " Standard stop failed, trying one more time..."
475
- sleep 5
476
- systemctl stop postgresql || true
477
- fi
478
-
479
- # Quick verification
480
- if systemctl is-active --quiet postgresql; then
481
- echo " WARNING: PostgreSQL service still active after stop commands"
482
- echo " You may need to investigate what's preventing proper shutdown"
483
- else
484
- echo " PostgreSQL successfully stopped"
468
+ systemctl disable postgresql
469
+
470
+ # Try graceful shutdown first
471
+ systemctl stop postgresql
472
+
473
+ # Add a verification loop to ensure the process is actually stopped
474
+ for i in {1..30}; do
475
+ if ! systemctl is-active --quiet postgresql; then
476
+ # Double check no postgres processes are running
477
+ if ! pgrep -x postgres > /dev/null; then
478
+ break
479
+ fi
485
480
fi
481
+ echo " Waiting for PostgreSQL to stop... attempt $i "
482
+ sleep 2
483
+ done
484
+
485
+ # If still running after 60 seconds, try one final forceful stop
486
+ if systemctl is-active --quiet postgresql; then
487
+ echo " PostgreSQL still running after graceful shutdown attempts, forcing stop..."
488
+ systemctl stop postgresql || true
489
+ sleep 5
490
+ fi
486
491
else
487
492
CI_stop_postgres
488
493
fi
0 commit comments