Hex / entrypoint.sh
OxMxO's picture
Update entrypoint.sh
4faa04e verified
raw
history blame
2.66 kB
#!/usr/bin/env bash
# ──────────────────────────────────────────────────────────────────────────────
# 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