diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml index 5ba7ef0..2dc654d 100644 --- a/.gitea/workflows/deploy.yml +++ b/.gitea/workflows/deploy.yml @@ -166,13 +166,31 @@ jobs: - name: Restart service & health check run: | - ssh $SSH_OPTS "${DEPLOY_USER}@${DEPLOY_HOST}" << REMOTE_SCRIPT + # Quoted heredoc: the loop's $i / $(seq) must be expanded on the + # REMOTE host, not by this runner's shell before it is sent. + ssh $SSH_OPTS "${DEPLOY_USER}@${DEPLOY_HOST}" << 'REMOTE_SCRIPT' set -e sudo systemctl restart signalplatform.service - sleep 3 - curl -fsS http://127.0.0.1:8998/api/v1/health > /dev/null \ - || { echo "✗ health check failed after restart"; exit 1; } - echo "✓ signalplatform deployed" + + # Poll instead of guessing how long startup takes. The old fixed + # "sleep 3" then single curl raced whenever startup ran long, and + # failed the deploy with a bare "connection refused" on a service + # that came up healthy a second later. This exits as soon as the app + # answers, so a fast start costs nothing. + for i in $(seq 1 60); do + if curl -fsS http://127.0.0.1:8998/api/v1/health > /dev/null 2>&1; then + echo "✓ signalplatform deployed — healthy after ${i}s" + exit 0 + fi + sleep 1 + done + + # Still down after a minute: this is a real failure, so leave enough + # behind to diagnose it without a second deploy. + echo "✗ health check failed: no response on :8998 after 60s" + sudo systemctl status signalplatform.service --no-pager -l || true + journalctl -u signalplatform.service -n 80 --no-pager || true + exit 1 REMOTE_SCRIPT - name: Clean up SSH key