一键部署:主程序+OCR同机(screen/GPU),Ollama外置局域网。

This commit is contained in:
dekun
2026-06-28 14:44:51 +08:00
parent 9713c640b4
commit 357f61c57c
13 changed files with 329 additions and 75 deletions
+9 -27
View File
@@ -1,10 +1,11 @@
#!/usr/bin/env bash
# 在带 NVIDIA 显卡的 Linux 机器上安装 OCR Worker
# 在带 NVIDIA 显卡的 Linux 机器上安装 OCR Worker(由 deploy/install.sh 自动调用)
set -euo pipefail
ROOT="$(cd "$(dirname "$0")" && pwd)"
VENV="${ROOT}/.venv"
PORT="${OCR_PORT:-23567}"
PIP_MIRROR="${PIP_MIRROR:-https://pypi.tuna.tsinghua.edu.cn/simple}"
echo "==> OCR Worker 安装目录: ${ROOT}"
@@ -21,7 +22,7 @@ fi
# shellcheck disable=SC1091
source "${VENV}/bin/activate"
pip install -U pip wheel
pip install -U pip wheel -i "${PIP_MIRROR}"
install_paddle() {
if command -v nvidia-smi >/dev/null 2>&1; then
@@ -39,35 +40,16 @@ install_paddle() {
fi
else
echo "==> 未检测到 GPU,安装 CPU 版 paddlepaddle…"
pip install paddlepaddle==2.6.2
pip install paddlepaddle==2.6.2 -i "${PIP_MIRROR}"
fi
}
install_paddle
pip install -r "${ROOT}/requirements.txt"
pip install -r "${ROOT}/requirements.txt" -i "${PIP_MIRROR}"
chmod +x "${ROOT}/run.sh" "${ROOT}/start.sh" 2>/dev/null || true
echo ""
echo "==> 验证依赖…"
python3 -c "import fastapi, uvicorn, paddle; print('paddle', paddle.__version__, 'OK')"
cat <<EOF
安装完成。
【重要】你已经在目录 ${ROOT} 时,不要再 cd deploy/ocr-worker,直接:
cd ${ROOT}
OCR_USE_GPU=true bash start.sh
另开终端测试(服务启动后):
curl -s http://127.0.0.1:${PORT}/health
应返回: {"status":"ok","gpu":true}
注册为 systemd 服务(推荐,后台常驻):
sudo bash ${ROOT}/install-service.sh
诊断:
bash ${ROOT}/check.sh
EOF
echo ""
echo "==> OCR Worker 安装完成。由 deploy/install.sh 通过 screen 自动启动。"
echo " 手动管理: bash $(dirname "$ROOT")/ocr-screen.sh status"
+32
View File
@@ -0,0 +1,32 @@
#!/usr/bin/env bash
# 供 screen 会话调用:OCR 模型常驻 GPU,异常退出自动重启
set -uo pipefail
ROOT="$(cd "$(dirname "$0")" && pwd)"
VENV="${ROOT}/.venv"
PORT="${OCR_PORT:-23567}"
export OCR_USE_GPU="${OCR_USE_GPU:-true}"
export OCR_HOST="${OCR_HOST:-0.0.0.0}"
if [[ ! -d "${VENV}" ]]; then
echo "错误: 请先运行 bash install.sh"
exit 1
fi
# shellcheck disable=SC1091
source "${VENV}/bin/activate"
cd "${ROOT}"
echo "=========================================="
echo " OCR Worker | GPU=${OCR_USE_GPU} | :${PORT}"
echo " $(date -Iseconds)"
echo " 退出 screen: Ctrl+A 然后 D"
echo "=========================================="
while true; do
uvicorn app:app --host "${OCR_HOST}" --port "${PORT}" --log-level info
code=$?
echo "[$(date -Iseconds)] uvicorn 退出 code=${code}5 秒后重启…"
sleep 5
done