Spaces:
Runtime error
Runtime error
Ashira Pitchayapakayakul commited on
Commit Β·
bdedae9
1
Parent(s): d4e26b2
SECURITY: disable set -x before .env source + verify uvicorn deps before exec
Browse files
start.sh
CHANGED
|
@@ -2,15 +2,17 @@
|
|
| 2 |
# Hermes start orchestrator for HF Space.
|
| 3 |
# Boots: persistent /data mount β Redis β Ollama β axentx repos β daemons β status server.
|
| 4 |
set -uo pipefail
|
| 5 |
-
# Trace ON for boot β finds hangs immediately. Disable later if logs too noisy.
|
| 6 |
-
PS4='[$(date +%H:%M:%S)] +${LINENO}: '
|
| 7 |
-
set -x
|
| 8 |
|
| 9 |
LOG_DIR="${HOME}/.claude/logs"
|
| 10 |
mkdir -p "$LOG_DIR"
|
| 11 |
echo "[$(date +%H:%M:%S)] hermes-hf-space boot start"
|
| 12 |
echo "[$(date +%H:%M:%S)] hermes-hf-space boot start" >> "$LOG_DIR/boot.log"
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
exec > >(tee -a "$LOG_DIR/boot.log") 2>&1
|
| 15 |
|
| 16 |
# ββ 1. Persistent data β symlink state dirs to /data (HF persistent mount) ββ
|
|
@@ -117,11 +119,15 @@ if ! ollama list 2>/dev/null | grep -q "gemma4:e4b"; then
|
|
| 117 |
fi
|
| 118 |
|
| 119 |
# ββ 6. Discord bot (background) βββββββββββββββββββββββββββββββββββββββββββββ
|
|
|
|
|
|
|
| 120 |
if [[ -n "${DISCORD_BOT_TOKEN:-}" ]]; then
|
| 121 |
-
set -a; source ~/.hermes/.env; set +a
|
| 122 |
nohup python ~/.claude/bin/hermes-discord-bot.py >> "$LOG_DIR/discord-bot.log" 2>&1 &
|
| 123 |
echo "[$(date +%H:%M:%S)] discord bot started" >> "$LOG_DIR/boot.log"
|
| 124 |
fi
|
|
|
|
|
|
|
| 125 |
|
| 126 |
# ββ 7. Cron loop β fires Hermes daemons 24/7 (no sleep gaps) ββββββββββββββββ
|
| 127 |
cat > /tmp/hermes-cron.sh <<'CRONSH'
|
|
@@ -149,7 +155,14 @@ nohup /tmp/hermes-cron.sh > "$LOG_DIR/cron-master.log" 2>&1 &
|
|
| 149 |
echo "[$(date +%H:%M:%S)] cron loop started" >> "$LOG_DIR/boot.log"
|
| 150 |
|
| 151 |
# ββ 8. Status HTTP server on :7860 (FastAPI/uvicorn β robust binding) ββββββ
|
| 152 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
|
| 154 |
# Run as PID 1 β uvicorn handles signals + auto-restart on crash
|
| 155 |
-
exec python3 ~/.claude/bin/hermes-status-server.py
|
|
|
|
| 2 |
# Hermes start orchestrator for HF Space.
|
| 3 |
# Boots: persistent /data mount β Redis β Ollama β axentx repos β daemons β status server.
|
| 4 |
set -uo pipefail
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
LOG_DIR="${HOME}/.claude/logs"
|
| 7 |
mkdir -p "$LOG_DIR"
|
| 8 |
echo "[$(date +%H:%M:%S)] hermes-hf-space boot start"
|
| 9 |
echo "[$(date +%H:%M:%S)] hermes-hf-space boot start" >> "$LOG_DIR/boot.log"
|
| 10 |
+
|
| 11 |
+
# Trace mode for early steps only (no secrets here yet) β find hang point but stay safe
|
| 12 |
+
PS4='[trace ${LINENO}] '
|
| 13 |
+
set -x
|
| 14 |
+
|
| 15 |
+
# Echo stdout so HF run-logs see progress (safe steps before .env is loaded)
|
| 16 |
exec > >(tee -a "$LOG_DIR/boot.log") 2>&1
|
| 17 |
|
| 18 |
# ββ 1. Persistent data β symlink state dirs to /data (HF persistent mount) ββ
|
|
|
|
| 119 |
fi
|
| 120 |
|
| 121 |
# ββ 6. Discord bot (background) βββββββββββββββββββββββββββββββββββββββββββββ
|
| 122 |
+
# π Disable shell trace BEFORE sourcing .env β never echo secrets to logs.
|
| 123 |
+
set +x
|
| 124 |
if [[ -n "${DISCORD_BOT_TOKEN:-}" ]]; then
|
| 125 |
+
set -a; source ~/.hermes/.env 2>/dev/null; set +a
|
| 126 |
nohup python ~/.claude/bin/hermes-discord-bot.py >> "$LOG_DIR/discord-bot.log" 2>&1 &
|
| 127 |
echo "[$(date +%H:%M:%S)] discord bot started" >> "$LOG_DIR/boot.log"
|
| 128 |
fi
|
| 129 |
+
# Re-enable trace AFTER secrets are sourced (variables in env, not echoed)
|
| 130 |
+
set -x
|
| 131 |
|
| 132 |
# ββ 7. Cron loop β fires Hermes daemons 24/7 (no sleep gaps) ββββββββββββββββ
|
| 133 |
cat > /tmp/hermes-cron.sh <<'CRONSH'
|
|
|
|
| 155 |
echo "[$(date +%H:%M:%S)] cron loop started" >> "$LOG_DIR/boot.log"
|
| 156 |
|
| 157 |
# ββ 8. Status HTTP server on :7860 (FastAPI/uvicorn β robust binding) ββββββ
|
| 158 |
+
set +x # silence trace for clean uvicorn logs
|
| 159 |
+
echo "[$(date +%H:%M:%S)] starting status server :7860" | tee -a "$LOG_DIR/boot.log"
|
| 160 |
+
|
| 161 |
+
# Verify deps before exec β print what's missing rather than silent crash
|
| 162 |
+
python3 -c "import fastapi, uvicorn; print(f' fastapi {fastapi.__version__} + uvicorn {uvicorn.__version__} ok')" || {
|
| 163 |
+
echo "β fastapi/uvicorn not importable β falling back to plain http.server"
|
| 164 |
+
exec python3 -m http.server 7860 --bind 0.0.0.0
|
| 165 |
+
}
|
| 166 |
|
| 167 |
# Run as PID 1 β uvicorn handles signals + auto-restart on crash
|
| 168 |
+
exec python3 ~/.claude/bin/hermes-status-server.py
|