108 lines
4.9 KiB
Bash
108 lines
4.9 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}"
|
|
# Force gateway bind to LAN (all interfaces) — required for Docker
|
|
export OPENCLAW_GATEWAY_BIND="lan"
|
|
|
|
echo "📌 OPENCLAW_TYPE = $OPENCLAW_TYPE"
|
|
echo "📌 FOXY_HOME = $FOXY_HOME"
|
|
echo "📌 OPENCLAW_GATEWAY_BIND = $OPENCLAW_GATEWAY_BIND"
|
|
|
|
# ─── 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."
|
|
|
|
# ─── Ensure gateway config is Docker-ready ────────────────────────────────────
|
|
OCCONFIG="$FOXY_HOME/openclaw.json"
|
|
if [ -f "$OCCONFIG" ]; then
|
|
echo "🔧 Patching OpenClaw config for Docker (LAN bind + Control UI)..."
|
|
python3 -c "
|
|
import json, sys
|
|
|
|
path = sys.argv[1]
|
|
with open(path, 'r') as f:
|
|
cfg = json.load(f)
|
|
|
|
# Ensure gateway section exists
|
|
gw = cfg.setdefault('gateway', {})
|
|
gw['bind'] = 'lan'
|
|
gw['mode'] = 'local'
|
|
|
|
# Control UI: required when bind != loopback
|
|
ui = gw.setdefault('controlUi', {})
|
|
ui['dangerouslyAllowHostHeaderOriginFallback'] = True
|
|
|
|
with open(path, 'w') as f:
|
|
json.dump(cfg, f, indent=2)
|
|
|
|
print(' ✅ gateway.bind = lan')
|
|
print(' ✅ gateway.mode = local')
|
|
print(' ✅ gateway.controlUi.dangerouslyAllowHostHeaderOriginFallback = true')
|
|
" "$OCCONFIG"
|
|
fi
|
|
|
|
# ─── Gateway startup ─────────────────────────────────────────────────────────
|
|
if [ "$OPENCLAW_TYPE" = "standalone" ]; then
|
|
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
echo "🚀 Starting OpenClaw Gateway (standalone, foreground mode)..."
|
|
echo ""
|
|
echo " Command: openclaw gateway run --bind lan --allow-unconfigured"
|
|
echo ""
|
|
|
|
# 'gateway run' = foreground mode (no systemd needed)
|
|
# '--bind lan' = listen on all interfaces (0.0.0.0) for Docker port mapping
|
|
# '--allow-unconfigured' = start even if gateway.mode!=local in config
|
|
nohup openclaw gateway run \
|
|
--bind lan \
|
|
--allow-unconfigured \
|
|
> "$FOXY_HOME/logs/gateway.log" 2>&1 &
|
|
GATEWAY_PID=$!
|
|
|
|
echo "⏱ Waiting for Gateway (PID $GATEWAY_PID) to initialize..."
|
|
|
|
# Wait up to 15 seconds for port 18789 to open
|
|
for i in $(seq 1 15); do
|
|
if netstat -tulpn 2>/dev/null | grep -q ":18789"; then
|
|
echo "✅ OpenClaw Gateway is UP — port 18789 is listening!"
|
|
break
|
|
fi
|
|
if ! kill -0 $GATEWAY_PID 2>/dev/null; then
|
|
echo "❌ Gateway process died!"
|
|
echo "──── Gateway Log ────"
|
|
tail -n 30 "$FOXY_HOME/logs/gateway.log" 2>/dev/null || echo "(no log)"
|
|
echo "─────────────────────"
|
|
break
|
|
fi
|
|
sleep 1
|
|
done
|
|
|
|
# Final check
|
|
if ! netstat -tulpn 2>/dev/null | grep -q ":18789"; then
|
|
echo "⚠️ Gateway may not be fully ready. Tail of log:"
|
|
tail -n 10 "$FOXY_HOME/logs/gateway.log" 2>/dev/null || true
|
|
echo "⚠️ Continuing anyway — 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
|