thread-master/stop-dev.sh

48 lines
2.0 KiB
Bash
Raw Normal View History

2026-06-28 08:28:42 +00:00
#!/bin/bash
set -e
echo "=== 停止巡樓開發環境服務 (保留 infra) ==="
# 1. 停止前端 dev server (Vite on :5173)
echo "[1/4] 停止前端 dev server..."
pkill -f "vite.*dev" 2>/dev/null && echo " ✓ Vite dev server 已停止" || echo " - Vite dev server 未在執行"
# 2. 停止 Node worker (style-8d)
echo "[2/4] 停止 Node worker (style-8d)..."
pkill -f "style-8d-worker" 2>/dev/null && echo " ✓ Node worker 已停止" || echo " - Node worker 未在執行"
pkill -f "tsx.*style-8d" 2>/dev/null && echo " ✓ tsx worker 已停止" || true
# 3. 停止 Go worker含編譯後殘留的 exe/worker 與 go run ./cmd/worker
echo "[3/4] 停止 Go worker..."
pkill -f "go run ./cmd/worker" 2>/dev/null || true
pkill -f "cmd/worker.*gateway.worker.yaml" 2>/dev/null || true
pkill -f "exe/worker -f etc/gateway.worker.yaml" 2>/dev/null || true
pkill -f "worker -f etc/gateway.worker.yaml" 2>/dev/null || true
if pgrep -f "gateway.worker.yaml" >/dev/null 2>&1; then
echo " ⚠ 仍有 worker 殘留,強制結束..."
pkill -9 -f "gateway.worker.yaml" 2>/dev/null || true
fi
echo " ✓ Go worker 已停止"
# 4. 停止 Go gateway (port 8890)
echo "[4/4] 停止 Go gateway..."
pkill -f "go run . -f etc/gateway.yaml" 2>/dev/null || true
pkill -f "exe/haixun-backend -f etc/gateway.yaml" 2>/dev/null || true
pkill -f "haixun-backend -f etc/gateway.yaml" 2>/dev/null || true
if pgrep -f "etc/gateway.yaml" >/dev/null 2>&1; then
echo " ⚠ 仍有 gateway 殘留,強制結束..."
pkill -9 -f "etc/gateway.yaml" 2>/dev/null || true
fi
echo " ✓ Go gateway 已停止"
# 5. 清理可能殘留的 port 佔用 (optional, 避免 port 衝突)
for port in 8890 8891 5173; do
if lsof -ti:$port >/dev/null 2>&1; then
echo " ⚠ Port $port 仍被佔用,強制釋放..."
lsof -ti:$port | xargs kill -9 2>/dev/null || true
fi
done
echo ""
echo "=== 開發環境服務已停止 (infra: Mongo/Redis 保持執行) ==="
echo "提示: 若需停止 infra請執行: make dev-infra-down"