Spaces:
Paused
Paused
Download docker-entrypoint.sh from immahadi/FreeLLMAPI: direct link, hf CLI and curl.
- Browser
- Download file 2.26 kB
-
https://huggingface.co/spaces/immahadi/FreeLLMAPI/resolve/main/docker-entrypoint.sh
- Command line
-
hf download hf://spaces/immahadi/FreeLLMAPI/docker-entrypoint.sh
-
curl -L -o docker-entrypoint.sh https://huggingface.co/spaces/immahadi/FreeLLMAPI/resolve/main/docker-entrypoint.sh
2.26 kB
| set -e | |
| DATA_DIR="${DATA_DIR:-/data}" | |
| mkdir -p "$DATA_DIR" 2>/dev/null || true | |
| # 1. Dynamic memory tuning for V8 heap limit | |
| if [ -n "$OMNIROUTE_MEMORY_MB" ]; then | |
| export NODE_OPTIONS="${NODE_OPTIONS:-} --max-old-space-size=${OMNIROUTE_MEMORY_MB}" | |
| fi | |
| # 2. Check for base path rewrite utility if baked in | |
| if [ -f docker/ensure-docker-base-path.mjs ]; then | |
| node docker/ensure-docker-base-path.mjs || true | |
| fi | |
| # 3. Pull persistent state from remote Hugging Face Dataset (if token configured) | |
| if [ -f /usr/local/bin/sync.py ]; then | |
| python3 /usr/local/bin/sync.py download || true | |
| fi | |
| # 4. Background periodic upload daemon | |
| SYNC_INTERVAL="${SYNC_INTERVAL:-300}" | |
| ACTIVE_HF_TOKEN="${HF_TOKEN:-${HUGGINGFACE_TOKEN:-${HUGGING_FACE_HUB_TOKEN:-${HF_ACCESS_TOKEN:-}}}}" | |
| if [ -n "$ACTIVE_HF_TOKEN" ]; then | |
| ( | |
| while true; do | |
| sleep "$SYNC_INTERVAL" | |
| python3 /usr/local/bin/sync.py upload PASSIVE || true | |
| done | |
| ) & | |
| SYNC_DAEMON_PID=$! | |
| fi | |
| # 5. Trap SIGTERM & SIGINT for safe SQLite checkpoint & final upload to dataset | |
| cleanup() { | |
| echo "[OmniRoute] Caught shutdown signal. Terminating child process..." | |
| if [ -n "$APP_PID" ]; then | |
| kill -TERM "$APP_PID" 2>/dev/null || true | |
| wait "$APP_PID" 2>/dev/null || true | |
| fi | |
| if [ -n "$SYNC_DAEMON_PID" ]; then | |
| kill -TERM "$SYNC_DAEMON_PID" 2>/dev/null || true | |
| fi | |
| echo "[OmniRoute] Committing final state to Hugging Face Dataset..." | |
| if [ -f /usr/local/bin/sync.py ]; then | |
| python3 /usr/local/bin/sync.py upload TRUNCATE || true | |
| fi | |
| echo "[OmniRoute] Container shutdown complete." | |
| exit 0 | |
| } | |
| trap cleanup TERM INT HUP | |
| # 6. Runtime startup banner | |
| echo "==========================================================" | |
| echo " Starting OmniRoute on Hugging Face Spaces" | |
| echo " Port: ${PORT:-7860}" | |
| echo " Host: ${HOSTNAME:-0.0.0.0}" | |
| echo " Data Directory: $DATA_DIR" | |
| echo " Dataset Storage: ${HF_DATASET_REPO:-userbymahadi/OmniRoute-storage}" | |
| echo " User ID: $(id -u):$(id -g)" | |
| echo "==========================================================" | |
| "$@" & | |
| APP_PID=$! | |
| wait "$APP_PID" | |
| EXIT_CODE=$? | |
| # Final flush on standard exit | |
| if [ -f /usr/local/bin/sync.py ]; then | |
| python3 /usr/local/bin/sync.py upload TRUNCATE || true | |
| fi | |
| exit $EXIT_CODE | |