feat: Add container startup script to initialize backend service and conditionally start OpenClaw Gateway, updating docker-compose.yml to use it.
This commit is contained in:
parent
a466e64247
commit
8056219f39
@ -7,8 +7,11 @@ echo "🦊 Starting Foxy Dev Team API Container..."
|
|||||||
export FOXY_HOME="${FOXY_HOME:-/home/foxy/.openclaw}"
|
export FOXY_HOME="${FOXY_HOME:-/home/foxy/.openclaw}"
|
||||||
export OPENCLAW_TYPE="${OPENCLAW_TYPE:-shared}"
|
export OPENCLAW_TYPE="${OPENCLAW_TYPE:-shared}"
|
||||||
|
|
||||||
|
# Ensure logs directory exists
|
||||||
|
mkdir -p "$FOXY_HOME/logs"
|
||||||
|
|
||||||
if [ "$OPENCLAW_TYPE" = "standalone" ]; then
|
if [ "$OPENCLAW_TYPE" = "standalone" ]; then
|
||||||
echo "🔧 OPENCLAW_TYPE is standalone. Setting up OpenClaw..."
|
echo "🔧 OPENCLAW_TYPE is standalone. Setting up internal OpenClaw Gateway..."
|
||||||
|
|
||||||
# Initialize OpenClaw default configuration if it doesn't exist
|
# Initialize OpenClaw default configuration if it doesn't exist
|
||||||
if [ ! -f "$FOXY_HOME/config.json" ] && [ ! -f "$FOXY_HOME/config.yaml" ]; then
|
if [ ! -f "$FOXY_HOME/config.json" ] && [ ! -f "$FOXY_HOME/config.yaml" ]; then
|
||||||
@ -16,29 +19,42 @@ if [ "$OPENCLAW_TYPE" = "standalone" ]; then
|
|||||||
mkdir -p "$FOXY_HOME/workspace"
|
mkdir -p "$FOXY_HOME/workspace"
|
||||||
mkdir -p "$FOXY_HOME/agents"
|
mkdir -p "$FOXY_HOME/agents"
|
||||||
|
|
||||||
# Write a simple default config if OpenClaw hasn't been onboarded
|
# Write a simple default config for Docker environment
|
||||||
cat <<EOF > "$FOXY_HOME/config.json"
|
cat <<EOF > "$FOXY_HOME/config.json"
|
||||||
{
|
{
|
||||||
"theme": "dark",
|
"theme": "dark",
|
||||||
"logLevel": "info",
|
"logLevel": "info",
|
||||||
"gatewayPort": 20124,
|
"gatewayPort": 18789,
|
||||||
"gatewayHost": "127.0.0.1",
|
"gatewayHost": "0.0.0.0",
|
||||||
"workspaceDir": "$FOXY_HOME/workspace",
|
"workspaceDir": "$FOXY_HOME/workspace",
|
||||||
"agentsDir": "$FOXY_HOME/agents"
|
"agentsDir": "$FOXY_HOME/agents"
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
echo "✅ Default configuration created."
|
echo "✅ Default configuration created (binding to 0.0.0.0)."
|
||||||
else
|
else
|
||||||
echo "👍 OpenClaw configuration already exists at $FOXY_HOME."
|
echo "👍 OpenClaw configuration already exists at $FOXY_HOME."
|
||||||
|
# Optional: ensure gatewayHost is 0.0.0.0 even in existing config if it's internal
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "🚀 Starting OpenClaw Gateway in the background..."
|
echo "🚀 Starting OpenClaw Gateway..."
|
||||||
# Starting OpenClaw gateway in the background so it doesn't block FastAPI
|
# Launching the gateway. If 'start' backgrounds itself we might need 'run' or similar.
|
||||||
|
# We use 'nohup' but we'll check it's alive.
|
||||||
if command -v openclaw >/dev/null 2>&1; then
|
if command -v openclaw >/dev/null 2>&1; then
|
||||||
nohup openclaw gateway start > "$FOXY_HOME/logs/gateway.log" 2>&1 &
|
# Some versions of openclaw use 'gateway run' or just 'gateway' for foreground
|
||||||
echo "✅ OpenClaw Gateway started."
|
nohup openclaw gateway start --host 0.0.0.0 > "$FOXY_HOME/logs/gateway.log" 2>&1 &
|
||||||
|
|
||||||
|
# Give it a second to start
|
||||||
|
sleep 2
|
||||||
|
|
||||||
|
if pgrep -f "openclaw" > /dev/null; then
|
||||||
|
echo "✅ OpenClaw Gateway started successfully."
|
||||||
|
else
|
||||||
|
echo "⚠️ Gateway didn't start with 'start' command, trying direct execution..."
|
||||||
|
# Fallback for some installations
|
||||||
|
nohup openclaw gateway > "$FOXY_HOME/logs/gateway.log" 2>&1 &
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
echo "❌ 'openclaw' command not found, unable to start gateway!"
|
echo "❌ 'openclaw' command not found!"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo "🔗 OPENCLAW_TYPE is shared. Assuming OpenClaw Gateway is managed by the host."
|
echo "🔗 OPENCLAW_TYPE is shared. Assuming OpenClaw Gateway is managed by the host."
|
||||||
|
|||||||
@ -20,6 +20,7 @@ services:
|
|||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
ports:
|
ports:
|
||||||
- "${API_PORT:-7000}:7000"
|
- "${API_PORT:-7000}:7000"
|
||||||
|
- "18789:18789"
|
||||||
env_file:
|
env_file:
|
||||||
- backend/.env
|
- backend/.env
|
||||||
environment:
|
environment:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user