Files
usa/start.sh
2026-03-03 17:54:43 +08:00

60 lines
1.6 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.
#!/usr/bin/env bash
# 一键启动 US-Iran 态势面板API + 前端 + 爬虫服务
set -e
cd "$(dirname "$0")"
# 若存在 .env 则加载(可在此设置 DASHSCOPE_API_KEY=sk-xxx勿提交 .env
[ -f .env ] && set -a && . ./.env && set +a
# AI 模式:有 DASHSCOPE_API_KEY 时用通义(商业模型,无需 Ollama否则用 Ollama 或规则
export CLEANER_AI_DISABLED=0
export PARSER_AI_DISABLED=0
# GDELT 国内常超时,仅用 RSS 更新(如需 GDELT 可改为 0
export GDELT_DISABLED=1
export RSS_INTERVAL_SEC=60
echo "==> Checking dependencies..."
[ ! -d node_modules ] && npm install
echo "==> Checking crawler Python deps..."
pip install -q -r crawler/requirements.txt 2>/dev/null || true
echo "==> Seeding database (if needed)..."
# 若指定了 DB_PATH则以 DB_PATH 为准;否则默认使用 server/data.db
DB_FILE_PATH="${DB_PATH:-server/data.db}"
if [ ! -f "$DB_FILE_PATH" ]; then
echo " - DB file not found at $DB_FILE_PATH, running api:seed once"
npm run api:seed
else
echo " - Existing DB detected at $DB_FILE_PATH, skip seeding"
fi
echo "==> Starting API (http://localhost:3001)..."
npm run api &
API_PID=$!
# 等待 API 就绪后再启动爬虫
sleep 2
echo "==> Starting GDELT/RSS crawler (http://localhost:8000)..."
npm run gdelt &
GDELT_PID=$!
echo "==> Starting frontend (Vite dev server)..."
npm run dev &
DEV_PID=$!
cleanup() {
echo ""
echo "==> Shutting down..."
kill $API_PID $GDELT_PID $DEV_PID 2>/dev/null || true
exit 0
}
trap cleanup SIGINT SIGTERM
echo ""
echo "==> All services running. Frontend: http://localhost:5173 | API: http://localhost:3001"
echo " Press Ctrl+C to stop all."
echo ""
wait