Files
PlantAI-rag-new/vstore/vstore_restart.sh
T
adminandClaude Fable 5 7037a1d5d8 fix(deploy): restart 脚本 lsof 只取 LISTEN 态进程
2026-09-12 部署实测:lsof -ti tcp:PORT 返回该端口上所有 socket 的
进程——包括 BFF 到 8098/8094 的已建立连接,不只监听者。kill 多行
PID 时旧进程存活、新进程绑定失败静默退出(vstore 报 address already
in use;生信 restart 后仍是旧进程)。改 -sTCP:LISTEN 只取监听者,
kill 不再加引号(多 PID 需分词)。

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-09-12 18:22:11 +08:00

45 lines
1.8 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
# vstore_restart.sh —— 向量库服务(8094)幂等重启(部署树与安装包共用,路径从脚本位置推导)
# 用法: bash vstore_restart.sh [python] [port]
# 说明: vstore 是包(部署根/vstore 目录),uvicorn 必须从父目录 -m vstore.api:app,
# cd 进 vstore/ 会导致 ModuleNotFoundError(先例注释保留)。
# 零硬编码:venv/python/数据根全部环境变量或脚本位置推导。
set -uo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # .../vstore
ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" # 部署根
PYTHON="${1:-${PLANTAI_PYTHON:-$ROOT/venv/bin/python}}"
PORT="${2:-${VSTORE_PORT:-8094}}"
HOST="${VSTORE_BIND_HOST:-127.0.0.1}"
[ -x "$PYTHON" ] || PYTHON="$(command -v python3 2>/dev/null || true)"
[ -n "$PYTHON" ] && [ -x "$PYTHON" ] || { echo "[vstore] Python 不可执行,请指定: vstore_restart.sh <python>" >&2; exit 2; }
# 杀旧进程([v]store 正则技巧防 pkill 自匹配;端口优先精确)
if command -v lsof >/dev/null 2>&1; then
OLD_PID="$(lsof -ti tcp:"$PORT" -sTCP:LISTEN 2>/dev/null || true)"
[ -n "$OLD_PID" ] && kill $OLD_PID 2>/dev/null || true
else
pkill -f "[v]store.api:app" 2>/dev/null || true
fi
sleep 2
cd "$ROOT"
set -a
[ -f "$SCRIPT_DIR/.env" ] && source "$SCRIPT_DIR/.env"
set +a
setsid "$PYTHON" -m uvicorn vstore.api:app --host "$HOST" --port "$PORT" \
> /tmp/plantai-vstore.log 2>&1 < /dev/null &
disown
sleep 8
if curl -s --max-time 5 "http://127.0.0.1:$PORT/api/vstore/health" | grep -q '"ok"'; then
echo "VSTORE UP ($HOST:$PORT)"
curl -s --max-time 5 "http://127.0.0.1:$PORT/api/vstore/health"
echo
else
echo "VSTORE FAIL —— 日志尾部:" >&2
tail -20 /tmp/plantai-vstore.log >&2 || true
exit 1
fi