diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml index 47afaff..08bef71 100644 --- a/.gitea/workflows/deploy.yml +++ b/.gitea/workflows/deploy.yml @@ -79,35 +79,16 @@ jobs: run: | cd /opt/zhixi/backend && npx prisma generate - - name: Start API service + - name: Restart API service run: | - cd /opt/zhixi/backend - PORT=3000 nohup node dist/main.js > /tmp/zhixi-direct.log 2>&1 & - DIRECT_PID=$! - HEALTHY=0 - for i in $(seq 1 15); do - sleep 1 - if curl -sf http://localhost:3000/api > /dev/null 2>&1; then - echo "[deploy] App healthy after ${i}s" - HEALTHY=1 - break - fi - if ! kill -0 $DIRECT_PID 2>/dev/null; then - echo "[deploy] App crashed — log:" - tail -30 /tmp/zhixi-direct.log - break - fi - done - kill $DIRECT_PID 2>/dev/null - wait $DIRECT_PID 2>/dev/null || true - if [ "$HEALTHY" = "1" ]; then - echo "[deploy] App verified OK, restarting via systemd..." - sudo systemctl reset-failed zhixi-api 2>/dev/null || true - sudo systemctl restart zhixi-api || true - sleep 3 - curl -sf http://localhost:3000/api > /dev/null && echo "[deploy] systemd health OK" || echo "[deploy] systemd restart pending (app verified working)" + sudo systemctl reset-failed zhixi-api 2>/dev/null || true + sudo systemctl restart zhixi-api + sleep 3 + if curl -sf http://localhost:3000/api > /dev/null 2>&1; then + echo "[deploy] API health OK" else - echo "[deploy] App failed to start" + echo "[deploy] Health check failed — checking logs:" + sudo journalctl -u zhixi-api --no-pager -n 20 exit 1 fi