#!/bin/bash set -e echo "🦊 Starting Foxy Dev Team API Container (Enhanced Mode)..." # Force HOME for consistent paths export HOME="/home/foxy" export FOXY_HOME="/home/foxy/.openclaw" export OPENCLAW_TYPE="${OPENCLAW_TYPE:-standalone}" # Ensure directories exist mkdir -p "$FOXY_HOME/logs" mkdir -p "$FOXY_HOME/workspace" mkdir -p "$FOXY_HOME/agents" # --- CONFIG PATCHING --- # We look for both possible filenames FILES=("$FOXY_HOME/config.json" "$FOXY_HOME/openclaw.json" "$FOXY_HOME/config.yaml" "$FOXY_HOME/openclaw.yaml") for CONFIG_FILE in "${FILES[@]}"; do if [ -f "$CONFIG_FILE" ]; then echo "🔧 Patching $CONFIG_FILE..." sed -i 's/\/home\/openclaw/\/home\/foxy/g' "$CONFIG_FILE" sed -i 's/"gatewayHost": "127.0.0.1"/"gatewayHost": "0.0.0.0"/g' "$CONFIG_FILE" sed -i 's/gatewayHost: 127.0.0.1/gatewayHost: 0.0.0.0/g' "$CONFIG_FILE" echo "✅ $CONFIG_FILE patched." fi done # Deep patch: search for any stray host paths in agents or other files echo "🔍 Searching for stray host paths in $FOXY_HOME..." find "$FOXY_HOME" -type f -not -path "*/logs/*" -exec sed -i 's/\/home\/openclaw/\/home\/foxy/g' {} + echo "✅ Recursive path patching complete." # If no config exists at all, create a default one if [ ! -f "$FOXY_HOME/config.json" ] && [ ! -f "$FOXY_HOME/openclaw.json" ] && [ ! -f "$FOXY_HOME/config.yaml" ] && [ ! -f "$FOXY_HOME/openclaw.yaml" ]; then echo "📦 No config found. Initializing default OpenClaw config..." cat < "$FOXY_HOME/openclaw.json" { "theme": "dark", "logLevel": "info", "gatewayPort": 18789, "gatewayHost": "0.0.0.0", "workspaceDir": "$FOXY_HOME/workspace", "agentsDir": "$FOXY_HOME/agents" } EOF fi # --- GATEWAY STARTUP --- if [ "$OPENCLAW_TYPE" = "standalone" ]; then echo "🔧 OPENCLAW_TYPE is standalone. Starting internal Gateway..." # Try to kill any existing (though unlikely in fresh container) pkill -f "openclaw" || true echo "🚀 Launching OpenClaw Gateway in background..." # We use 'nohup' and target 0.0.0.0 explicitly. # Redirecting to a persistent log file. nohup openclaw gateway start --host 0.0.0.0 --port 18789 > "$FOXY_HOME/logs/gateway.log" 2>&1 & # Wait and check echo "⏱ Waiting for Gateway to initialize..." sleep 5 if pgrep -f "openclaw" > /dev/null; then echo "✅ OpenClaw Gateway process found (PID: $(pgrep -f "openclaw"))." # Optional: check if port is listening if command -v netstat >/dev/null 2>&1; then netstat -tulpn | grep 18789 || echo "⚠️ Gateway started but port 18789 not yet listening." fi else echo "❌ OpenClaw Gateway crashed or failed to start!" echo "--- LAST LOGS ---" tail -n 20 "$FOXY_HOME/logs/gateway.log" echo "-----------------" fi else echo "🔗 OPENCLAW_TYPE is shared. Assuming host gateway." fi echo "🚀 Starting Uvicorn API Server..." # We don't use 'exec' here so that this script stays as a parent # OR we do use exec if tini is the entrypoint (it will handle orphans). # Using exec is better for signal propagation. exec python -m uvicorn app.main:app --host 0.0.0.0 --port 7000