Files
PlantAI-rag-new/deploy/bff_restart.sh
T

46 lines
1.9 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
# deploy/bff_restart.sh —— 远端 BFF 重启(PM 使用,在远端执行)
# 用法:ssh 192.168.0.175 -p 26518 'bash ~/5090/teamWorkspace/zh/PlantAI-rag-new/deploy/bff_restart.sh [bind_addr]'
# 参数:可选绑定地址(默认 127.0.0.1;内网演示传 0.0.0.0)
# 要点:用 setsid 完全脱离 SSH 会话,stdout/stderr 全部落日志。
# 2026-09-01 统一 Python:conda plantai-bff → plantai-rag-new-venv(py3.12.13)
set -uo pipefail
SDK_ROOT="/home/xzq/5090/teamWorkspace/zh/plantai-rag-new-deploy-unified/sdk"
PYTHON="/home/xzq/5090/teamWorkspace/zh/plantai-rag-new-venv/bin/python"
BIND="${1:-127.0.0.1}"
[[ -x "$PYTHON" ]] || { echo "BFF Python 不可执行: $PYTHON" >&2; exit 1; }
# 杀旧进程:按 8090 端口精确匹配(TL 2026-09-06 修——
# 旧 pkill 模式 "app.main:app" 会误杀 8098 生信服务,两者同为 uvicorn app.main:app)
if command -v lsof >/dev/null 2>&1; then
OLD_PID="$(lsof -ti tcp:8090 2>/dev/null || true)"
[ -n "$OLD_PID" ] && kill "$OLD_PID" 2>/dev/null || true
else
pkill -f "[a]pp.main:app.*--port 8090" 2>/dev/null || true
fi
sleep 2
cd "$SDK_ROOT"
# 加载运行时凭据(sdk/.env,不入 git)并导出给应用进程。
# pydantic-settings 会把 .env 载入 settings 对象,但 services/neo4j.py 的
# _env() 直接读 os.environ,故需显式 set -a 导出。
set -a
[ -f .env ] && source .env
set +a
setsid "$PYTHON" -m uvicorn app.main:app --host "$BIND" --port 8090 \
> /tmp/plantai-bff.log 2>&1 < /dev/null &
disown
sleep 12
if ss -tln | grep -q ":8090 "; then
echo "BFF UP ($BIND:8090, venv py3.12.13)"
curl -s --max-time 20 http://127.0.0.1:8090/api/health | head -c 200
echo
# 生产形态:静态托管 ui/dist(存在时 BFF 单进程服务整个前端)
curl -s --max-time 10 http://127.0.0.1:8090/ | grep -o "<title>[^<]*" || echo "(静态托管未生效,需同步 dist)"
else
echo "BFF FAIL —— 日志尾部:"
tail -15 /tmp/plantai-bff.log
exit 1
fi