File size: 2,215 Bytes
d42d358
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/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