Spaces:
Build error
Build error
Add entrypoint.sh to start ZeroClaw, Memgraph, OmniRoute, Graph Viewer, Marimo
Browse files- scripts/entrypoint.sh +115 -0
scripts/entrypoint.sh
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
|
| 3 |
+
# Centralized Logging Configuration
|
| 4 |
+
export LOG_LEVEL=${LOG_LEVEL:-"info"}
|
| 5 |
+
export LOG_FILE=${LOG_FILE:-"/app/verdant_claw.log"}
|
| 6 |
+
|
| 7 |
+
# Mask sensitive env vars in logs
|
| 8 |
+
log() {
|
| 9 |
+
local msg=$(echo "$1" | sed -E 's/(nvapi|sk|gsk)[a-zA-Z0-9]+/\1*****/g')
|
| 10 |
+
echo "[$(date -u +"%Y-%m-%dT%H:%M:%SZ")] [$LOG_LEVEL] $msg" | tee -a $LOG_FILE
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
# Trap SIGTERM for graceful shutdown
|
| 14 |
+
cleanup() {
|
| 15 |
+
log "Shutting down services gracefully..."
|
| 16 |
+
kill $(jobs -p) 2>/dev/null
|
| 17 |
+
sleep 2
|
| 18 |
+
log "Shutdown complete"
|
| 19 |
+
exit 0
|
| 20 |
+
}
|
| 21 |
+
trap cleanup SIGTERM SIGINT
|
| 22 |
+
|
| 23 |
+
# Parse API_KEYS_JSON secret
|
| 24 |
+
if [ -n "$API_KEYS_JSON" ]; then
|
| 25 |
+
log "Parsing API keys from JSON..."
|
| 26 |
+
export NVIDIA_API_KEY=$(echo $API_KEYS_JSON | jq -r '.nvidia // empty')
|
| 27 |
+
export OPENAI_API_KEY=$(echo $API_KEYS_JSON | jq -r '.openai // empty')
|
| 28 |
+
export ANTHROPIC_API_KEY=$(echo $API_KEYS_JSON | jq -r '.anthropic // empty')
|
| 29 |
+
export GOOGLE_API_KEY=$(echo $API_KEYS_JSON | jq -r '.google // empty')
|
| 30 |
+
export GROQ_API_KEY=$(echo $API_KEYS_JSON | jq -r '.groq // empty')
|
| 31 |
+
log "✓ API keys loaded from JSON"
|
| 32 |
+
else
|
| 33 |
+
log "⚠️ WARNING: API_KEYS_JSON not set!"
|
| 34 |
+
fi
|
| 35 |
+
|
| 36 |
+
# Function to start service with retry
|
| 37 |
+
start_with_retry() {
|
| 38 |
+
local name=$1
|
| 39 |
+
local cmd=$2
|
| 40 |
+
local max_attempts=3
|
| 41 |
+
|
| 42 |
+
for i in $(seq 1 $max_attempts); do
|
| 43 |
+
log "Starting $name (attempt $i/$max_attempts)..."
|
| 44 |
+
eval "$cmd" &
|
| 45 |
+
local pid=$!
|
| 46 |
+
sleep 5
|
| 47 |
+
if ps -p $pid > /dev/null; then
|
| 48 |
+
log "✓ $name started (PID: $pid)"
|
| 49 |
+
return 0
|
| 50 |
+
fi
|
| 51 |
+
log "⚠️ $name failed to start, retrying..."
|
| 52 |
+
done
|
| 53 |
+
|
| 54 |
+
log "❌ ERROR: $name failed after $max_attempts attempts"
|
| 55 |
+
return 1
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
# Check if ports are available
|
| 59 |
+
check_port() {
|
| 60 |
+
local port=$1
|
| 61 |
+
if netstat -tlnp 2>/dev/null | grep -q ":$port"; then
|
| 62 |
+
log "❌ ERROR: Port $port already in use!"
|
| 63 |
+
return 1
|
| 64 |
+
fi
|
| 65 |
+
return 0
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
log "Verifying infrastructure ports..."
|
| 69 |
+
for port in 7860 7861 7687 20128; do
|
| 70 |
+
check_port $port || exit 1
|
| 71 |
+
done
|
| 72 |
+
|
| 73 |
+
# 🚀 Start Services
|
| 74 |
+
MEMGRAPH_BIN=$(command -v memgraph || echo "/usr/bin/memgraph")
|
| 75 |
+
if [ ! -f "$MEMGRAPH_BIN" ]; then
|
| 76 |
+
MEMGRAPH_BIN="/usr/lib/memgraph/memgraph"
|
| 77 |
+
fi
|
| 78 |
+
|
| 79 |
+
start_with_retry "Memgraph" "$MEMGRAPH_BIN --bolt-port 7687" || exit 1
|
| 80 |
+
|
| 81 |
+
# Start ZeroClaw on port 7862
|
| 82 |
+
export ZEROCLAW_PORT=7862
|
| 83 |
+
start_with_retry "ZeroClaw" "zeroclaw gateway" || exit 1
|
| 84 |
+
|
| 85 |
+
start_with_retry "OmniRoute" "node /app/scripts/omniroute.js --config /app/config/omniroute-masterfile.json --port 20128" || exit 1
|
| 86 |
+
|
| 87 |
+
# Start Graph Viewer on port 7861
|
| 88 |
+
GRAPH_VIEWER_PORT=7861 start_with_retry "Graph Viewer" "node /app/scripts/graph-viewer.js" || exit 1
|
| 89 |
+
|
| 90 |
+
log "All infrastructure ready! Launching Gradio UI on port 7860..."
|
| 91 |
+
|
| 92 |
+
# Launch Gradio app (NOT Marimo)
|
| 93 |
+
cd /app
|
| 94 |
+
nohup python3 app.py > /tmp/gradio.log 2>&1 &
|
| 95 |
+
GRADIO_PID=$!
|
| 96 |
+
sleep 3
|
| 97 |
+
if ps -p $GRADIO_PID > /dev/null; then
|
| 98 |
+
log "✓ Gradio started (PID: $GRADIO_PID)"
|
| 99 |
+
log " Gradio logs: /tmp/gradio.log"
|
| 100 |
+
else
|
| 101 |
+
log "❌ ERROR: Gradio failed to start!"
|
| 102 |
+
cat /tmp/gradio.log
|
| 103 |
+
exit 1
|
| 104 |
+
fi
|
| 105 |
+
|
| 106 |
+
log "All services active!"
|
| 107 |
+
log " - Memgraph: port 7687"
|
| 108 |
+
log " - ZeroClaw: port 7862"
|
| 109 |
+
log " - OmniRoute: port 20128"
|
| 110 |
+
log " - Graph Viewer: port 7861"
|
| 111 |
+
log " - Gradio UI: port 7860 (primary)"
|
| 112 |
+
|
| 113 |
+
# Keep container alive
|
| 114 |
+
log "Holding container open. Access the UI at https://your-space.hf.space"
|
| 115 |
+
wait
|