install: show wait progress, shorten OCR health wait, log to file.
This commit is contained in:
+6
-1
@@ -212,7 +212,7 @@ setup_ocr_gpu() {
|
|||||||
fi
|
fi
|
||||||
install_ocr_worker
|
install_ocr_worker
|
||||||
start_ocr_screen
|
start_ocr_screen
|
||||||
wait_ocr_healthy || log_warn "OCR 仍在加载模型,稍后可执行: bash ${INSTALL_DIR}/deploy/ocr-screen.sh status"
|
wait_ocr_healthy 30 || log_warn "OCR 后台加载中,继续安装主程序…"
|
||||||
}
|
}
|
||||||
|
|
||||||
stop_legacy_pm2() {
|
stop_legacy_pm2() {
|
||||||
@@ -240,13 +240,18 @@ start_service() {
|
|||||||
|
|
||||||
wait_healthy() {
|
wait_healthy() {
|
||||||
local i
|
local i
|
||||||
|
log_info "等待主程序就绪(最多 2 分钟)…"
|
||||||
for i in $(seq 1 40); do
|
for i in $(seq 1 40); do
|
||||||
if curl -sf "http://127.0.0.1:${WEB_PORT}/api/health" >/dev/null; then
|
if curl -sf "http://127.0.0.1:${WEB_PORT}/api/health" >/dev/null; then
|
||||||
log_info "主程序健康检查通过"
|
log_info "主程序健康检查通过"
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
if (( i % 5 == 0 )); then
|
||||||
|
echo -ne "\r${YELLOW}[INFO]${NC} 等待主程序… ${i}/40"
|
||||||
|
fi
|
||||||
sleep 3
|
sleep 3
|
||||||
done
|
done
|
||||||
|
echo ""
|
||||||
log_warn "主程序健康检查超时: journalctl -u grade-archive -f"
|
log_warn "主程序健康检查超时: journalctl -u grade-archive -f"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+16
-6
@@ -41,12 +41,16 @@ start_ocr_screen() {
|
|||||||
sleep 1
|
sleep 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
screen -dmS "${OCR_SCREEN_NAME}" bash -lc "
|
mkdir -p "${INSTALL_DIR}/logs" 2>/dev/null || true
|
||||||
|
local log_file="${INSTALL_DIR}/logs/ocr-worker.log"
|
||||||
|
|
||||||
|
screen -dmS "${OCR_SCREEN_NAME}" bash -c "
|
||||||
cd '${worker_dir}' &&
|
cd '${worker_dir}' &&
|
||||||
export OCR_USE_GPU=true OCR_PORT='${OCR_PORT}' OCR_HOST=0.0.0.0 &&
|
export OCR_USE_GPU=true OCR_PORT='${OCR_PORT}' OCR_HOST=0.0.0.0 &&
|
||||||
exec bash run.sh
|
exec bash run.sh >> '${log_file}' 2>&1
|
||||||
"
|
"
|
||||||
sleep 1
|
sleep 2
|
||||||
|
log_info "OCR 日志: ${log_file}"
|
||||||
}
|
}
|
||||||
|
|
||||||
stop_ocr_screen() {
|
stop_ocr_screen() {
|
||||||
@@ -57,16 +61,22 @@ stop_ocr_screen() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
wait_ocr_healthy() {
|
wait_ocr_healthy() {
|
||||||
|
local max="${1:-30}"
|
||||||
local i
|
local i
|
||||||
for i in $(seq 1 90); do
|
log_info "等待 OCR 就绪(最多 ${max}×2 秒,首次加载模型较慢)…"
|
||||||
|
for i in $(seq 1 "${max}"); do
|
||||||
if curl -sf "http://127.0.0.1:${OCR_PORT}/health" >/dev/null 2>&1; then
|
if curl -sf "http://127.0.0.1:${OCR_PORT}/health" >/dev/null 2>&1; then
|
||||||
log_info "OCR 健康检查通过 — http://127.0.0.1:${OCR_PORT}/health"
|
log_info "OCR 健康检查通过 — http://127.0.0.1:${OCR_PORT}/health"
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
if (( i % 5 == 0 )); then
|
||||||
|
echo -ne "\r${YELLOW}[INFO]${NC} 仍在等待 OCR… ${i}/${max}(可另开终端: tail -f ${INSTALL_DIR}/logs/ocr-worker.log)"
|
||||||
|
fi
|
||||||
sleep 2
|
sleep 2
|
||||||
done
|
done
|
||||||
log_warn "OCR 尚未就绪(模型加载可能需 1–3 分钟)"
|
echo ""
|
||||||
log_warn "查看: bash ${INSTALL_DIR}/deploy/ocr-screen.sh status"
|
log_warn "OCR 尚未响应(可能仍在下载/加载模型,主程序可先继续)"
|
||||||
|
log_warn "稍后执行: bash ${INSTALL_DIR}/deploy/ocr-screen.sh status"
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -110,27 +110,14 @@ def run_ocr_on_bytes(content: bytes) -> dict:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@app.on_event("startup")
|
|
||||||
def warmup():
|
|
||||||
"""延迟预热,不阻塞 HTTP 服务启动。"""
|
|
||||||
import threading
|
|
||||||
|
|
||||||
def _run():
|
|
||||||
buf = __import__("io").BytesIO()
|
|
||||||
Image.new("RGB", (120, 40), color=(255, 255, 255)).save(buf, format="JPEG")
|
|
||||||
try:
|
|
||||||
run_ocr_on_bytes(buf.getvalue())
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
|
|
||||||
threading.Thread(target=_run, daemon=True, name="ocr-warmup").start()
|
|
||||||
|
|
||||||
|
|
||||||
@app.get("/health")
|
@app.get("/health")
|
||||||
def health():
|
def health():
|
||||||
return {"status": "ok", "gpu": OCR_USE_GPU}
|
return {"status": "ok", "gpu": OCR_USE_GPU}
|
||||||
|
|
||||||
|
|
||||||
|
# 首次 /api/ocr/regions 请求时再加载模型(/health 立即响应,避免安装脚本长时间等待)
|
||||||
|
|
||||||
|
|
||||||
@app.post("/api/ocr/regions")
|
@app.post("/api/ocr/regions")
|
||||||
async def ocr_regions(
|
async def ocr_regions(
|
||||||
file: UploadFile = File(...),
|
file: UploadFile = File(...),
|
||||||
|
|||||||
Reference in New Issue
Block a user