Files
adminandClaude Fable 5 dbe2037116 chore(deploy): 向量化本地模型(Ollama+bge-m3)纳入部署脚本
- deploy/ollama_restart.sh(新): Ollama 幂等拉起+嵌入模型校验,二进制多候选
  探测(零硬编码),模型缺失只告警不阻断;start_all.sh 在四服务前先拉起
- vstore/vstore_restart.sh(新): 部署树与安装包共用版(路径从脚本位置推导,
  零硬编码),替换部署树旧硬编码脚本(实测重启后 210 文档+210 chunks 完整)
- build_all.sh: 组装段纳入 vstore 明文源码+启动脚本+env 模板;start_all.sh
  heredoc 增加 Ollama 拉起段——安装包自此包含向量化环节

实测: ollama_restart.sh 幂等(已运行跳过,bge-m3 就绪);vstore 新脚本重启
UP(210/210);bash -n 全过。

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-09-08 00:46:31 +08:00

46 lines
1.9 KiB
Bash
Executable File
Raw Permalink 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
# ollama_restart.sh —— 向量化本地模型服务(Ollama + bge-m3 嵌入)幂等拉起
# 用途:部署树与安装包共用;start_all.sh 在启动各服务前调用。
# 零硬编码:Ollama 二进制多候选探测(PATH → /usr/local/bin/ollama → ~/ollama/bin/ollama → $OLLAMA_BIN)。
# 行为:已监听 11434 则直接校验模型并返回;未起才拉起(setsid 脱离,日志 /tmp/plantai-ollama.log)。
# 用法: bash ollama_restart.sh [embed-model]
set -uo pipefail
MODEL="${1:-${VSTORE_EMBED_MODEL:-bge-m3:567m}}"
PORT="${OLLAMA_PORT:-11434}"
OLLAMA_BIN="${OLLAMA_BIN:-}"
find_ollama() {
for cand in "$OLLAMA_BIN" /usr/local/bin/ollama "$HOME/ollama/bin/ollama"; do
[ -n "$cand" ] && [ -x "$cand" ] && { echo "$cand"; return 0; }
done
command -v ollama 2>/dev/null || true
}
OLLAMA_BIN="$(find_ollama)"
if [ -z "$OLLAMA_BIN" ]; then
echo "[ollama] 未找到 Ollama 二进制(/usr/local/bin/ollama 或 ~/ollama/bin/ollama),向量化将不可用" >&2
echo "[ollama] 安装:https://ollama.com/download/linux,然后 ollama pull $MODEL" >&2
exit 2
fi
if curl -s --max-time 2 "http://127.0.0.1:$PORT/api/tags" >/dev/null 2>&1; then
echo "[ollama] 已在运行($OLLAMA_BIN,端口 $PORT),跳过拉起"
else
echo "[ollama] 拉起本地模型服务($OLLAMA_BIN)"
setsid "$OLLAMA_BIN" serve > /tmp/plantai-ollama.log 2>&1 < /dev/null &
disown
for _ in $(seq 1 30); do
sleep 1
curl -s --max-time 2 "http://127.0.0.1:$PORT/api/tags" >/dev/null 2>&1 && break
done
fi
# 嵌入模型校验(向量化必需:bge-m3;缺失给出拉取命令,不阻断其他服务启动)
if curl -s --max-time 5 "http://127.0.0.1:$PORT/api/tags" | grep -q "\"name\":\"$MODEL\""; then
echo "[ollama] 嵌入模型 $MODEL 就绪"
else
echo "[ollama] 警告:嵌入模型 $MODEL 未安装,向量化/私有资料检索将降级" >&2
echo "[ollama] 安装命令:$OLLAMA_BIN pull $MODEL" >&2
fi