feat: Add script to start the backend container.
This commit is contained in:
parent
973705e8f1
commit
2d76efdf46
@ -1,86 +1,99 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
echo "🦊 Starting Foxy Dev Team API Container (Enhanced Mode)..."
|
echo "🦊 Starting Foxy Dev Team API Container..."
|
||||||
|
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||||
|
|
||||||
# Force HOME for consistent paths
|
# ─── Environment ──────────────────────────────────────────────────────────────
|
||||||
export HOME="/home/foxy"
|
export HOME="/home/foxy"
|
||||||
export FOXY_HOME="/home/foxy/.openclaw"
|
export FOXY_HOME="/home/foxy/.openclaw"
|
||||||
export OPENCLAW_TYPE="${OPENCLAW_TYPE:-standalone}"
|
export OPENCLAW_TYPE="${OPENCLAW_TYPE:-standalone}"
|
||||||
|
|
||||||
# Ensure directories exist
|
echo "📌 OPENCLAW_TYPE = $OPENCLAW_TYPE"
|
||||||
mkdir -p "$FOXY_HOME/logs"
|
echo "📌 FOXY_HOME = $FOXY_HOME"
|
||||||
mkdir -p "$FOXY_HOME/workspace"
|
|
||||||
mkdir -p "$FOXY_HOME/agents"
|
|
||||||
|
|
||||||
# --- CONFIG PATCHING ---
|
# ─── Ensure directories ──────────────────────────────────────────────────────
|
||||||
# We look for both possible filenames
|
mkdir -p "$FOXY_HOME/logs" "$FOXY_HOME/workspace" "$FOXY_HOME/agents"
|
||||||
FILES=("$FOXY_HOME/config.json" "$FOXY_HOME/openclaw.json" "$FOXY_HOME/config.yaml" "$FOXY_HOME/openclaw.yaml")
|
|
||||||
|
|
||||||
for CONFIG_FILE in "${FILES[@]}"; do
|
# ─── Config patching ─────────────────────────────────────────────────────────
|
||||||
if [ -f "$CONFIG_FILE" ]; then
|
# Fix host paths (/home/openclaw → /home/foxy) in all config & agent files
|
||||||
echo "🔧 Patching $CONFIG_FILE..."
|
echo "🔧 Patching host paths for container environment..."
|
||||||
sed -i 's/\/home\/openclaw/\/home\/foxy/g' "$CONFIG_FILE"
|
find "$FOXY_HOME" -type f \( -name "*.json" -o -name "*.yaml" -o -name "*.yml" \) \
|
||||||
sed -i 's/"gatewayHost": "127.0.0.1"/"gatewayHost": "0.0.0.0"/g' "$CONFIG_FILE"
|
-not -path "*/logs/*" \
|
||||||
sed -i 's/gatewayHost: 127.0.0.1/gatewayHost: 0.0.0.0/g' "$CONFIG_FILE"
|
-not -path "*/node_modules/*" \
|
||||||
echo "✅ $CONFIG_FILE patched."
|
-exec sed -i 's/\/home\/openclaw/\/home\/foxy/g' {} + 2>/dev/null || true
|
||||||
fi
|
echo "✅ Path patching complete."
|
||||||
done
|
|
||||||
|
|
||||||
# Deep patch: search for any stray host paths in agents or other files
|
# ─── Ensure gateway.bind is set to 0.0.0.0 in config ─────────────────────────
|
||||||
echo "🔍 Searching for stray host paths in $FOXY_HOME..."
|
# OpenClaw uses openclaw.json as its config file
|
||||||
find "$FOXY_HOME" -type f -not -path "*/logs/*" -exec sed -i 's/\/home\/openclaw/\/home\/foxy/g' {} +
|
OCCONFIG="$FOXY_HOME/openclaw.json"
|
||||||
echo "✅ Recursive path patching complete."
|
|
||||||
|
|
||||||
# If no config exists at all, create a default one
|
if [ -f "$OCCONFIG" ]; then
|
||||||
if [ ! -f "$FOXY_HOME/config.json" ] && [ ! -f "$FOXY_HOME/openclaw.json" ] && [ ! -f "$FOXY_HOME/config.yaml" ] && [ ! -f "$FOXY_HOME/openclaw.yaml" ]; then
|
echo "🔧 Ensuring gateway binds to 0.0.0.0 in $OCCONFIG..."
|
||||||
echo "📦 No config found. Initializing default OpenClaw config..."
|
# Replace any 127.0.0.1 binding with 0.0.0.0 so Docker can expose the port
|
||||||
cat <<EOF > "$FOXY_HOME/openclaw.json"
|
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"
|
||||||
"theme": "dark",
|
# Also handle the gateway.host key if present
|
||||||
"logLevel": "info",
|
sed -i 's/"host"[[:space:]]*:[[:space:]]*"127.0.0.1"/"host": "0.0.0.0"/g' "$OCCONFIG"
|
||||||
"gatewayPort": 18789,
|
|
||||||
"gatewayHost": "0.0.0.0",
|
|
||||||
"workspaceDir": "$FOXY_HOME/workspace",
|
|
||||||
"agentsDir": "$FOXY_HOME/agents"
|
|
||||||
}
|
|
||||||
EOF
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# --- GATEWAY STARTUP ---
|
# ─── 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 ─────────────────────────────────────────────────────────
|
||||||
if [ "$OPENCLAW_TYPE" = "standalone" ]; then
|
if [ "$OPENCLAW_TYPE" = "standalone" ]; then
|
||||||
echo "🔧 OPENCLAW_TYPE is standalone. Starting internal Gateway..."
|
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||||
|
echo "🚀 Starting OpenClaw Gateway (standalone)..."
|
||||||
# Try to kill any existing (though unlikely in fresh container)
|
|
||||||
pkill -f "openclaw" || true
|
# Kill any leftover process
|
||||||
|
pkill -f "openclaw" 2>/dev/null || true
|
||||||
echo "🚀 Launching OpenClaw Gateway in background..."
|
sleep 1
|
||||||
# We use 'nohup' and target 0.0.0.0 explicitly.
|
|
||||||
# Redirecting to a persistent log file.
|
# Start gateway — NO --host flag (doesn't exist).
|
||||||
nohup openclaw gateway start --host 0.0.0.0 --port 18789 > "$FOXY_HOME/logs/gateway.log" 2>&1 &
|
# Binding is controlled via openclaw.json gateway.bind setting.
|
||||||
|
nohup openclaw gateway start > "$FOXY_HOME/logs/gateway.log" 2>&1 &
|
||||||
# Wait and check
|
GATEWAY_PID=$!
|
||||||
echo "⏱ Waiting for Gateway to initialize..."
|
|
||||||
|
echo "⏱ Waiting for Gateway (PID $GATEWAY_PID) to initialize..."
|
||||||
sleep 5
|
sleep 5
|
||||||
|
|
||||||
if pgrep -f "openclaw" > /dev/null; then
|
# Check if process is alive
|
||||||
echo "✅ OpenClaw Gateway process found (PID: $(pgrep -f "openclaw"))."
|
if kill -0 $GATEWAY_PID 2>/dev/null; then
|
||||||
# Optional: check if port is listening
|
echo "✅ OpenClaw Gateway is running (PID $GATEWAY_PID)."
|
||||||
if command -v netstat >/dev/null 2>&1; then
|
# Check port
|
||||||
netstat -tulpn | grep 18789 || echo "⚠️ Gateway started but port 18789 not yet listening."
|
if netstat -tulpn 2>/dev/null | grep -q 18789; then
|
||||||
|
echo "✅ Port 18789 is listening."
|
||||||
|
else
|
||||||
|
echo "⚠️ Gateway running but port 18789 not yet open. It may need more time."
|
||||||
|
echo " Check logs: cat $FOXY_HOME/logs/gateway.log"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo "❌ OpenClaw Gateway crashed or failed to start!"
|
echo "❌ OpenClaw Gateway failed to start!"
|
||||||
echo "--- LAST LOGS ---"
|
echo "──── Gateway Log ────"
|
||||||
tail -n 20 "$FOXY_HOME/logs/gateway.log"
|
cat "$FOXY_HOME/logs/gateway.log" 2>/dev/null || echo "(no log)"
|
||||||
echo "-----------------"
|
echo "─────────────────────"
|
||||||
|
echo "⚠️ Continuing without Gateway. API will still start."
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo "🔗 OPENCLAW_TYPE is shared. Assuming host gateway."
|
echo "🔗 OPENCLAW_TYPE is shared — expecting host-managed Gateway."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "🚀 Starting Uvicorn API Server..."
|
# ─── Start API ────────────────────────────────────────────────────────────────
|
||||||
# We don't use 'exec' here so that this script stays as a parent
|
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||||
# OR we do use exec if tini is the entrypoint (it will handle orphans).
|
echo "🚀 Starting Uvicorn API Server on port 7000..."
|
||||||
# Using exec is better for signal propagation.
|
|
||||||
exec python -m uvicorn app.main:app --host 0.0.0.0 --port 7000
|
exec python -m uvicorn app.main:app --host 0.0.0.0 --port 7000
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user