Spaces:
Running
Running
| # start.sh | |
| # Boots FastAPI (background) then Nginx (foreground) inside the container. | |
| set -e | |
| echo "ποΈ Survival Island startingβ¦" | |
| echo " HF_MODEL : ${HF_MODEL:-not set}" | |
| echo " HF_TOKEN : ${HF_TOKEN:+set (hidden)}" | |
| echo " PORT : ${PORT:-7860}" | |
| # ββ 1. Start FastAPI on port 8000 (background) ββββββββββββββββββββββββββββββββ | |
| uvicorn server.app:app \ | |
| --host 127.0.0.1 \ | |
| --port 8000 \ | |
| --workers 1 \ | |
| --log-level info & | |
| UVICORN_PID=$! | |
| # ββ 2. Wait until FastAPI is healthy (up to 30 s) βββββββββββββββββββββββββββββ | |
| echo "β³ Waiting for FastAPI health checkβ¦" | |
| for i in $(seq 1 30); do | |
| if curl -sf http://127.0.0.1:8000/api/health > /dev/null 2>&1; then | |
| echo "β FastAPI ready after ${i}s." | |
| break | |
| fi | |
| sleep 1 | |
| done | |
| # ββ 3. Start Nginx in foreground (keeps the container alive) ββββββββββββββββββ | |
| echo "π Nginx serving on :${PORT:-7860}" | |
| nginx -g "daemon off;" | |
| # ββ 4. Cleanup on exit ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| echo "Nginx exited. Stopping uvicornβ¦" | |
| kill "$UVICORN_PID" 2>/dev/null || true | |