From 837e6fac9d22e1e828a9c53ea3d63878ab275eab Mon Sep 17 00:00:00 2001 From: juanatsap Date: Thu, 9 Apr 2026 23:10:47 +0100 Subject: [PATCH] fix: deploy waits for port 1999 to be free before starting service --- .github/workflows/deploy.yml | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index be419bc..cb9a7f4 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -75,10 +75,28 @@ jobs: sudo cp config/systemd/cv.service /etc/systemd/system/$SERVICE_NAME.service sudo systemctl daemon-reload - echo "🔄 Restarting service..." - sudo systemctl restart $SERVICE_NAME + echo "🔄 Stopping service..." + sudo systemctl stop $SERVICE_NAME || true - echo "⏳ Waiting for service to start..." + # Wait for port to be released (max 15s) + echo "⏳ Waiting for port 1999 to be free..." + for i in $(seq 1 15); do + if ! sudo fuser 1999/tcp >/dev/null 2>&1; then + echo "✅ Port 1999 free after ${i}s" + break + fi + if [ $i -eq 15 ]; then + echo "⚠️ Force-killing port 1999..." + sudo fuser -k 1999/tcp 2>/dev/null || true + sleep 1 + fi + sleep 1 + done + + echo "🔄 Starting service..." + sudo systemctl start $SERVICE_NAME + + echo "⏳ Waiting for health check..." sleep 3 # Check service status