thread-master/start-dev.sh

94 lines
3.0 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
set -e
echo "=== 啟動巡樓開發環境服務 (不含 infra) ==="
echo "前置條件: infra (Mongo/Redis) 必須已啟動,請先執行: make dev-infra"
echo ""
# 檢查 infra 是否運行
if ! docker compose -f infra/docker-compose.yml ps --status running 2>/dev/null | grep -q "mongo\|redis"; then
echo "⚠️ 警告: infra (Mongo/Redis) 似乎未運行"
echo " 請先執行: make dev-infra"
echo ""
read -p "是否繼續啟動服務? (y/N): " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
exit 1
fi
fi
# 1. 啟動 Go gateway (port 8890) - 背景執行
echo "[1/4] 啟動 Go gateway (:8890)..."
cd backend
if [ ! -f etc/gateway.yaml ]; then
echo " ✗ 找不到 etc/gateway.yaml"
exit 1
fi
nohup go run . -f etc/gateway.yaml > /tmp/haixun-gateway.log 2>&1 &
GATEWAY_PID=$!
cd ..
sleep 2
if kill -0 $GATEWAY_PID 2>/dev/null; then
echo " ✓ Gateway 已啟動 (PID: $GATEWAY_PID, log: /tmp/haixun-gateway.log)"
else
echo " ✗ Gateway 啟動失敗,查看日誌: cat /tmp/haixun-gateway.log"
exit 1
fi
# 2. Go job worker 已內嵌在 gatewayetc/gateway.yaml JobWorker.Enabled=true
echo "[2/4] Go job worker..."
echo " ✓ 使用 gateway 內嵌 worker勿另開 cmd/worker避免殘留舊進程搶 job"
# 3. 啟動 Node worker (style-8d) - 背景執行
echo "[3/4] 啟動 Node worker (style-8d)..."
cd backend/worker
if [ ! -f package.json ]; then
echo " ✗ 找不到 package.json"
exit 1
fi
export HAIXUN_WORKER_SECRET=haixun-dev-worker-secret
export HAIXUN_BACKEND_URL=http://127.0.0.1:8890
nohup npm run style-8d > /tmp/haixun-node-worker.log 2>&1 &
NODE_WORKER_PID=$!
cd ../..
sleep 3
if kill -0 $NODE_WORKER_PID 2>/dev/null; then
echo " ✓ Node worker 已啟動 (PID: $NODE_WORKER_PID, log: /tmp/haixun-node-worker.log)"
else
echo " ✗ Node worker 啟動失敗,查看日誌: cat /tmp/haixun-node-worker.log"
exit 1
fi
# 4. 啟動前端 dev server (port 5173) - 背景執行
echo "[4/4] 啟動前端 dev server (:5173)..."
cd frontend
if [ ! -f package.json ]; then
echo " ✗ 找不到 package.json"
exit 1
fi
nohup npm run dev > /tmp/haixun-frontend.log 2>&1 &
FRONTEND_PID=$!
cd ..
sleep 3
if kill -0 $FRONTEND_PID 2>/dev/null; then
echo " ✓ 前端已啟動 (PID: $FRONTEND_PID, log: /tmp/haixun-frontend.log)"
else
echo " ✗ 前端啟動失敗,查看日誌: cat /tmp/haixun-frontend.log"
exit 1
fi
echo ""
echo "=== 所有開發環境服務已啟動 ==="
echo ""
echo "服務狀態:"
echo " Gateway (API): http://localhost:8890 (PID: $GATEWAY_PID, 內嵌 Go worker)"
echo " Node Worker: style-8d worker (PID: $NODE_WORKER_PID)"
echo " Frontend (Vite): http://localhost:5173 (PID: $FRONTEND_PID)"
echo ""
echo "日誌檔案:"
echo " Gateway: tail -f /tmp/haixun-gateway.log"
echo " Node Worker: tail -f /tmp/haixun-node-worker.log"
echo " Frontend: tail -f /tmp/haixun-frontend.log"
echo ""
echo "停止所有服務: ./stop-dev.sh"
echo "查看 infra make dev-infra # 或 docker compose -f infra/docker-compose.yml ps"