node-2 / entrypoint.sh
sfdghsdvxfbgn's picture
Upload 7 files
d42d358 verified
Raw
History Blame Contribute Delete
2.22 kB
#!/usr/bin/env bash
# ─────────────────────────────────────────────────────────────────────────────
# MinerU OCR Service β€” container entrypoint
#
# Sequence:
# 1. Restore magic-pdf.json if wiped (HF container restart)
# 2. Run validate.py (pre-flight dependency check)
# β†’ exits 1 and kills container if any critical dep is missing
# β†’ this surfaces a clear error in HF logs instead of a silent bad start
# 3. Start uvicorn (single worker β€” CPU Basic, no RAM contention)
# ─────────────────────────────────────────────────────────────────────────────
set -e
CONFIG_FILE="${HOME}/magic-pdf.json"
# ── 1. Restore config if /root was wiped (HF container restart) ───────────────
if [ ! -f "$CONFIG_FILE" ]; then
echo "[entrypoint] magic-pdf.json missing β€” restoring from baked copy..."
cp /app/config/magic-pdf.json "$CONFIG_FILE"
fi
echo "[entrypoint] Config : $CONFIG_FILE"
echo "[entrypoint] Port : ${PORT:-7860}"
# ── 2. Pre-flight validation ──────────────────────────────────────────────────
# validate.py exits 0 on pass, exits 1 on any CRITICAL failure.
# 'set -e' above ensures a non-zero exit from validate.py aborts this script,
# preventing a broken uvicorn from starting and appearing healthy.
echo "[entrypoint] Running pre-flight validation..."
python /app/validate.py
echo "[entrypoint] Validation passed."
# ── 3. Start API server ───────────────────────────────────────────────────────
echo "[entrypoint] Starting uvicorn on 0.0.0.0:${PORT:-7860}..."
exec uvicorn main:app \
--host 0.0.0.0 \
--port "${PORT:-7860}" \
--workers 1 \
--timeout-keep-alive 120 \
--log-level info