Spaces:
Running
Running
| # ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| # Boots, in order: | |
| # 1) hexstrike_server.py β HTTP API on 127.0.0.1:8888 (loopback only) | |
| # 2) app.py β FastAPI + Gradio on 0.0.0.0:7860 | |
| # (which itself spawns mcp-proxy on 127.0.0.1:8765 | |
| # and reverse-proxies /servers/hexstrike/* onto it) | |
| # ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| set -euo pipefail | |
| if [[ -z "${HEXSTRIKE_TOKEN:-}" ]]; then | |
| echo "[entrypoint] FATAL: HEXSTRIKE_TOKEN secret is not set in the Space." | |
| echo " Add it under Settings β Variables and secrets β New secret." | |
| echo " Generate one with: openssl rand -hex 32" | |
| exit 1 | |
| fi | |
| if [[ -z "${HF_TOKEN:-}" ]]; then | |
| echo "[entrypoint] WARNING: HF_TOKEN secret is not set. Chat UI loads but" | |
| echo " will refuse to call the LLM until you set it." | |
| fi | |
| # ββ 1) HexStrike HTTP API on loopback only ββββββββββββββββββββββββββββββββββ | |
| cd /home/user/app/hexstrike | |
| python3 hexstrike_server.py --port 8888 >/tmp/hexstrike.log 2>&1 & | |
| HEX_PID=$! | |
| echo "[entrypoint] hexstrike_server.py started (pid=$HEX_PID), waiting for /healthβ¦" | |
| for i in {1..60}; do | |
| if curl -fsS http://127.0.0.1:8888/health >/dev/null 2>&1; then | |
| echo "[entrypoint] β HexStrike API is up after ${i}s" | |
| break | |
| fi | |
| sleep 1 | |
| done | |
| if ! curl -fsS http://127.0.0.1:8888/health >/dev/null 2>&1; then | |
| echo "[entrypoint] β HexStrike failed to start within 60s. Last 100 log lines:" | |
| tail -n 100 /tmp/hexstrike.log || true | |
| exit 1 | |
| fi | |
| # ββ 2) FastAPI + Gradio app (spawns mcp-proxy internally) ββββββββββββββββββββ | |
| cd /home/user/app | |
| if [[ ! -f app.py ]]; then | |
| echo "[entrypoint] β FATAL: /home/user/app/app.py is missing from the image." | |
| echo " Either app.py wasn't committed, or HF cached an old layer." | |
| echo " Click 'Factory rebuild' in the Space Settings to force a" | |
| echo " cache-free rebuild. Files present in /home/user/app:" | |
| ls -la /home/user/app | |
| exit 1 | |
| fi | |
| echo "[entrypoint] π Starting app.py (Gradio chat + MCP reverse proxy) on :7860" | |
| exec python3 app.py | |