Skip to content

Commit ae9b76d

Browse files
committed
feat: better shutdown handling
1 parent 4c393d7 commit ae9b76d

File tree

1 file changed

+22
-17
lines changed
  • ansible/files/admin_api_scripts/pg_upgrade_scripts

1 file changed

+22
-17
lines changed

ansible/files/admin_api_scripts/pg_upgrade_scripts/initiate.sh

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -465,24 +465,29 @@ EOF
465465
# Stop PostgreSQL service
466466
if [ -z "$IS_CI" ]; then
467467
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
485480
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
486491
else
487492
CI_stop_postgres
488493
fi

0 commit comments

Comments
 (0)