Files
gangyan/scripts/pdf-convert-service.sh

50 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
# 本地 PDF→Markdown 微服务(与 langchain file_converter.pdf_to_html 约定一致,默认 :6006
# 依赖 conda 环境 langchain-chat含 fastapi、uvicorn、PyMuPDF
[ -n "${BASH_VERSION:-}" ] || exec /usr/bin/env bash "$0" ${1+"$@"}
set -u
source "$(cd "$(dirname "$0")" && pwd)/common-restart.sh"
LOG_FILE="$LOG_DIR/pdf-convert-service.log"
LC_ROOT="$GANGYAN_ROOT/langchain-chat"
CONDA_SH="/opt/software/miniconda3/etc/profile.d/conda.sh"
log_line() {
local s="[$(date '+%Y-%m-%d %H:%M:%S')] $*"
echo "$s" >> "$LOG_FILE"
echo "$s"
}
log_line "======== 停止 pdf-convert-service (6006) ========"
pkill -f "uvicorn.*pdf_convert_service\.app:app" 2>/dev/null || true
sleep 1
if command -v lsof >/dev/null 2>&1; then
for pid in $(lsof -ti :6006 -sTCP:LISTEN 2>/dev/null || true); do
kill -TERM "$pid" 2>/dev/null && log_line "TERM pid=$pid :6006"
done
sleep 1
for pid in $(lsof -ti :6006 -sTCP:LISTEN 2>/dev/null || true); do
kill -KILL "$pid" 2>/dev/null && log_line "KILL pid=$pid :6006"
done
fi
log_line "======== 启动 pdf-convert-service ========"
if [ ! -f "$CONDA_SH" ]; then
log_line "错误: 未找到 $CONDA_SH"
exit 1
fi
# shellcheck source=/dev/null
source "$CONDA_SH"
conda activate langchain-chat
cd "$LC_ROOT"
export PYTHONPATH="$LC_ROOT"
export PDF_CONVERT_KB_ROOT="${PDF_CONVERT_KB_ROOT:-$LC_ROOT/knowledge_base}"
export PDF_CONVERT_HOST="${PDF_CONVERT_HOST:-127.0.0.1}"
export PDF_CONVERT_PORT="${PDF_CONVERT_PORT:-6006}"
nohup python -m uvicorn pdf_convert_service.app:app \
--host "$PDF_CONVERT_HOST" --port "$PDF_CONVERT_PORT" \
>> "$LOG_FILE" 2>&1 &
log_line "已后台启动 PID=$! 监听 ${PDF_CONVERT_HOST}:${PDF_CONVERT_PORT}"
log_line "日志: $LOG_FILE KB_ROOT=$PDF_CONVERT_KB_ROOT"
log_line "健康检查: curl -sS http://${PDF_CONVERT_HOST}:${PDF_CONVERT_PORT}/health"