HF-SaaS / scripts /entrypoint.sh
luizcireno-crypto
docs: comprehensive documentation and inline comments across all files
85d93ea
raw
history blame
2.32 kB
#!/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