feat: Add script to start the backend container.

This commit is contained in:
Bruno Charest 2026-03-13 15:45:38 -04:00
parent 2d76efdf46
commit f81e394005

View File

@ -24,68 +24,37 @@ find "$FOXY_HOME" -type f \( -name "*.json" -o -name "*.yaml" -o -name "*.yml" \
-exec sed -i 's/\/home\/openclaw/\/home\/foxy/g' {} + 2>/dev/null || true -exec sed -i 's/\/home\/openclaw/\/home\/foxy/g' {} + 2>/dev/null || true
echo "✅ Path patching complete." echo "✅ Path patching complete."
# ─── Ensure gateway.bind is set to 0.0.0.0 in config ─────────────────────────
# OpenClaw uses openclaw.json as its config file
OCCONFIG="$FOXY_HOME/openclaw.json"
if [ -f "$OCCONFIG" ]; then
echo "🔧 Ensuring gateway binds to 0.0.0.0 in $OCCONFIG..."
# Replace any 127.0.0.1 binding with 0.0.0.0 so Docker can expose the port
sed -i 's/"bind"[[:space:]]*:[[:space:]]*"loopback"/"bind": "all"/g' "$OCCONFIG"
sed -i 's/"bind"[[:space:]]*:[[:space:]]*"127.0.0.1"/"bind": "0.0.0.0"/g' "$OCCONFIG"
# Also handle the gateway.host key if present
sed -i 's/"host"[[:space:]]*:[[:space:]]*"127.0.0.1"/"host": "0.0.0.0"/g' "$OCCONFIG"
fi
# ─── Default config if none exists ────────────────────────────────────────────
if [ ! -f "$OCCONFIG" ]; then
echo "📦 No openclaw.json found. Creating default configuration..."
cat <<'DEFAULTEOF' > "$OCCONFIG"
{
"gateway": {
"port": 18789,
"bind": "all"
},
"agents": {
"directory": "/home/foxy/.openclaw/agents"
},
"workspace": "/home/foxy/.openclaw/workspace"
}
DEFAULTEOF
echo "✅ Default openclaw.json created."
fi
# ─── Gateway startup ───────────────────────────────────────────────────────── # ─── Gateway startup ─────────────────────────────────────────────────────────
if [ "$OPENCLAW_TYPE" = "standalone" ]; then if [ "$OPENCLAW_TYPE" = "standalone" ]; then
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "🚀 Starting OpenClaw Gateway (standalone)..." echo "🚀 Starting OpenClaw Gateway (standalone, foreground mode)..."
# Kill any leftover process # Use 'gateway run' (foreground) instead of 'gateway start' (systemd).
pkill -f "openclaw" 2>/dev/null || true # --bind lan : listen on all interfaces (required for Docker port mapping)
sleep 1 # --port 18789 : explicit port
nohup openclaw gateway run --bind lan --port 18789 > "$FOXY_HOME/logs/gateway.log" 2>&1 &
# Start gateway — NO --host flag (doesn't exist).
# Binding is controlled via openclaw.json gateway.bind setting.
nohup openclaw gateway start > "$FOXY_HOME/logs/gateway.log" 2>&1 &
GATEWAY_PID=$! GATEWAY_PID=$!
echo "⏱ Waiting for Gateway (PID $GATEWAY_PID) to initialize..." echo "⏱ Waiting for Gateway (PID $GATEWAY_PID) to initialize..."
sleep 5 sleep 5
# Check if process is alive
if kill -0 $GATEWAY_PID 2>/dev/null; then if kill -0 $GATEWAY_PID 2>/dev/null; then
echo "✅ OpenClaw Gateway is running (PID $GATEWAY_PID)." echo "✅ OpenClaw Gateway is running (PID $GATEWAY_PID)."
# Check port
if netstat -tulpn 2>/dev/null | grep -q 18789; then if netstat -tulpn 2>/dev/null | grep -q 18789; then
echo "✅ Port 18789 is listening." echo "✅ Port 18789 is listening."
else else
echo "⚠️ Gateway running but port 18789 not yet open. It may need more time." echo "⚠️ Port 18789 not yet open. Waiting 5 more seconds..."
echo " Check logs: cat $FOXY_HOME/logs/gateway.log" 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 fi
else else
echo "❌ OpenClaw Gateway failed to start!" echo "❌ OpenClaw Gateway failed to start!"
echo "──── Gateway Log ────" echo "──── Gateway Log ────"
cat "$FOXY_HOME/logs/gateway.log" 2>/dev/null || echo "(no log)" tail -n 30 "$FOXY_HOME/logs/gateway.log" 2>/dev/null || echo "(no log)"
echo "─────────────────────" echo "─────────────────────"
echo "⚠️ Continuing without Gateway. API will still start." echo "⚠️ Continuing without Gateway. API will still start."
fi fi