From c704aa8622c098bc790265371063acaa11d6b346 Mon Sep 17 00:00:00 2001 From: Bruno Charest Date: Fri, 13 Mar 2026 15:54:56 -0400 Subject: [PATCH] feat: Add backend container startup script. --- backend/start-container.sh | 62 ++++++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 26 deletions(-) diff --git a/backend/start-container.sh b/backend/start-container.sh index cb9fa40..4635d10 100644 --- a/backend/start-container.sh +++ b/backend/start-container.sh @@ -8,9 +8,12 @@ echo "━━━━━━━━━━━━━━━━━━━━━━━━ 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_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" @@ -28,35 +31,42 @@ echo "✅ Path patching complete." if [ "$OPENCLAW_TYPE" = "standalone" ]; then echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━" echo "🚀 Starting OpenClaw Gateway (standalone, foreground mode)..." + echo "" + echo " Command: openclaw gateway run --bind lan --allow-unconfigured" + echo "" - # 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 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..." - 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 + + # 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 - 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." + 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."