Spaces:
Running
Running
File size: 2,324 Bytes
6af979f 85d93ea 6af979f 85d93ea 6af979f 85d93ea 6af979f 85d93ea 6af979f 85d93ea 6af979f 85d93ea 6af979f | 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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | #!/bin/bash
# ============================================================
# HF-VPS β Container Entrypoint
#
# This script runs once when the Docker container starts.
# It prepares the environment and hands off to supervisord,
# which then manages all services for the container lifetime.
#
# Execution order:
# 1. Create runtime directories (logs, data, public)
# 2. Create /app/.env placeholder (HF Secrets flow in as real env vars)
# 3. Print version info for diagnostics in HF logs
# 4. Validate Nginx config (catches config errors before startup)
# 5. exec supervisord (replaces this process β keeps PID 1 clean)
#
# set -e: exit immediately on any error (fail fast, visible in HF logs)
# ============================================================
set -e
echo "============================================"
echo " HF-VPS Starting..."
echo "============================================"
# --- Create required runtime directories ---
# /app/logs β all service logs (supervisord, nginx, fastapi, redis, etc.)
# /app/data β SQLite database files and Redis dump.rdb
# /app/public β static files served at / and /static/ by Nginx
mkdir -p /app/logs /app/data /app/public
# --- Create .env placeholder ---
# HF Space Secrets are injected as real environment variables by HF.
# This empty .env ensures python-dotenv doesn't error if it looks for the file.
if [ ! -f /app/.env ]; then
touch /app/.env
fi
# --- Print version info (visible in HF Space container logs) ---
echo "[init] Python: $(python --version)"
echo "[init] Node: $(node --version)"
echo "[init] npm: $(npm --version)"
echo "[init] Redis: $(redis-server --version | head -1)"
echo "[init] Nginx: $(nginx -v 2>&1)"
# --- Validate Nginx config before starting ---
# nginx -t checks the config syntax without starting Nginx.
# If config is invalid, we warn but continue (supervisord will handle the error).
nginx -t 2>/dev/null && echo "[init] Nginx config OK" || echo "[init] WARNING: Nginx config check failed"
# --- Hand off to supervisord ---
# exec replaces the shell process with supervisord (keeps PID 1 clean).
# supervisord starts all services defined in its config (redis, fastapi, scheduler, nginx).
echo "[init] Starting all services..."
exec supervisord -c /etc/supervisor/conf.d/supervisord.conf
|