foxy-dev-team/backend/start-container.sh

69 lines
3.7 KiB
Bash

#!/bin/bash
set -e
echo "🦊 Starting Foxy Dev Team API Container..."
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
# ─── Environment ──────────────────────────────────────────────────────────────
export HOME="/home/foxy"
export FOXY_HOME="/home/foxy/.openclaw"
export OPENCLAW_TYPE="${OPENCLAW_TYPE:-standalone}"
echo "📌 OPENCLAW_TYPE = $OPENCLAW_TYPE"
echo "📌 FOXY_HOME = $FOXY_HOME"
# ─── Ensure directories ──────────────────────────────────────────────────────
mkdir -p "$FOXY_HOME/logs" "$FOXY_HOME/workspace" "$FOXY_HOME/agents"
# ─── Config patching ─────────────────────────────────────────────────────────
# Fix host paths (/home/openclaw → /home/foxy) in all config & agent files
echo "🔧 Patching host paths for container environment..."
find "$FOXY_HOME" -type f \( -name "*.json" -o -name "*.yaml" -o -name "*.yml" \) \
-not -path "*/logs/*" \
-not -path "*/node_modules/*" \
-exec sed -i 's/\/home\/openclaw/\/home\/foxy/g' {} + 2>/dev/null || true
echo "✅ Path patching complete."
# ─── Gateway startup ─────────────────────────────────────────────────────────
if [ "$OPENCLAW_TYPE" = "standalone" ]; then
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "🚀 Starting OpenClaw Gateway (standalone, foreground mode)..."
# Use 'gateway run' (foreground) instead of 'gateway start' (systemd).
# --bind lan : listen on all interfaces (required for Docker port mapping)
# --port 18789 : explicit port
nohup openclaw gateway run --bind lan --port 18789 > "$FOXY_HOME/logs/gateway.log" 2>&1 &
GATEWAY_PID=$!
echo "⏱ Waiting for Gateway (PID $GATEWAY_PID) to initialize..."
sleep 5
if kill -0 $GATEWAY_PID 2>/dev/null; then
echo "✅ OpenClaw Gateway is running (PID $GATEWAY_PID)."
if netstat -tulpn 2>/dev/null | grep -q 18789; then
echo "✅ Port 18789 is listening."
else
echo "⚠️ Port 18789 not yet open. Waiting 5 more seconds..."
sleep 5
if netstat -tulpn 2>/dev/null | grep -q 18789; then
echo "✅ Port 18789 is now listening."
else
echo "⚠️ Port still not open. Check: cat $FOXY_HOME/logs/gateway.log"
fi
fi
else
echo "❌ OpenClaw Gateway failed to start!"
echo "──── Gateway Log ────"
tail -n 30 "$FOXY_HOME/logs/gateway.log" 2>/dev/null || echo "(no log)"
echo "─────────────────────"
echo "⚠️ Continuing without Gateway. API will still start."
fi
else
echo "🔗 OPENCLAW_TYPE is shared — expecting host-managed Gateway."
fi
# ─── Start API ────────────────────────────────────────────────────────────────
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "🚀 Starting Uvicorn API Server on port 7000..."
exec python -m uvicorn app.main:app --host 0.0.0.0 --port 7000