feat: Add start-container.sh for container initialization, config patching, and orchestrating backend service startup.
This commit is contained in:
parent
dd163fec87
commit
973705e8f1
@ -36,6 +36,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
|
|||||||
net-tools \
|
net-tools \
|
||||||
iproute2 \
|
iproute2 \
|
||||||
nano \
|
nano \
|
||||||
|
tini \
|
||||||
&& mkdir -p /etc/apt/keyrings \
|
&& mkdir -p /etc/apt/keyrings \
|
||||||
&& curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg \
|
&& curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg \
|
||||||
&& echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_22.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list \
|
&& echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_22.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list \
|
||||||
@ -80,4 +81,6 @@ EXPOSE 7000
|
|||||||
|
|
||||||
USER foxy
|
USER foxy
|
||||||
|
|
||||||
|
ENTRYPOINT ["/usr/bin/tini", "--"]
|
||||||
|
|
||||||
CMD ["./start-container.sh"]
|
CMD ["./start-container.sh"]
|
||||||
|
|||||||
@ -1,39 +1,41 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
echo "🦊 Starting Foxy Dev Team API Container..."
|
echo "🦊 Starting Foxy Dev Team API Container (Enhanced Mode)..."
|
||||||
|
|
||||||
# Defaults
|
# Force HOME for consistent paths
|
||||||
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 logs directory exists
|
# Ensure directories exist
|
||||||
mkdir -p "$FOXY_HOME/logs"
|
mkdir -p "$FOXY_HOME/logs"
|
||||||
|
mkdir -p "$FOXY_HOME/workspace"
|
||||||
|
mkdir -p "$FOXY_HOME/agents"
|
||||||
|
|
||||||
# --- CONFIG PATCHING ---
|
# --- CONFIG PATCHING ---
|
||||||
# If we have a config file, we must ensure it doesn't point to host-specific paths
|
# We look for both possible filenames
|
||||||
# that don't exist in the container (like /home/openclaw)
|
FILES=("$FOXY_HOME/config.json" "$FOXY_HOME/openclaw.json" "$FOXY_HOME/config.yaml" "$FOXY_HOME/openclaw.yaml")
|
||||||
CONFIG_FILE=""
|
|
||||||
if [ -f "$FOXY_HOME/config.json" ]; then CONFIG_FILE="$FOXY_HOME/config.json"; fi
|
|
||||||
if [ -f "$FOXY_HOME/config.yaml" ]; then CONFIG_FILE="$FOXY_HOME/config.yaml"; fi
|
|
||||||
|
|
||||||
if [ -n "$CONFIG_FILE" ]; then
|
for CONFIG_FILE in "${FILES[@]}"; do
|
||||||
echo "🔧 Patching OpenClaw config paths for container environment..."
|
if [ -f "$CONFIG_FILE" ]; then
|
||||||
# Replace any /home/openclaw with /home/foxy in the config file
|
echo "🔧 Patching $CONFIG_FILE..."
|
||||||
sed -i 's/\/home\/openclaw/\/home\/foxy/g' "$CONFIG_FILE"
|
sed -i 's/\/home\/openclaw/\/home\/foxy/g' "$CONFIG_FILE"
|
||||||
echo "✅ Paths updated to /home/foxy in $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
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
# --- GATEWAY STARTUP ---
|
# Deep patch: search for any stray host paths in agents or other files
|
||||||
if [ "$OPENCLAW_TYPE" = "standalone" ]; then
|
echo "🔍 Searching for stray host paths in $FOXY_HOME..."
|
||||||
echo "🔧 OPENCLAW_TYPE is standalone. Starting internal Gateway..."
|
find "$FOXY_HOME" -type f -not -path "*/logs/*" -exec sed -i 's/\/home\/openclaw/\/home\/foxy/g' {} +
|
||||||
|
echo "✅ Recursive path patching complete."
|
||||||
|
|
||||||
# Initialize default config if none found
|
# If no config exists at all, create a default one
|
||||||
if [ -z "$CONFIG_FILE" ]; then
|
if [ ! -f "$FOXY_HOME/config.json" ] && [ ! -f "$FOXY_HOME/openclaw.json" ] && [ ! -f "$FOXY_HOME/config.yaml" ] && [ ! -f "$FOXY_HOME/openclaw.yaml" ]; then
|
||||||
echo "📦 Initializing default config..."
|
echo "📦 No config found. Initializing default OpenClaw config..."
|
||||||
mkdir -p "$FOXY_HOME/workspace" "$FOXY_HOME/agents"
|
cat <<EOF > "$FOXY_HOME/openclaw.json"
|
||||||
cat <<EOF > "$FOXY_HOME/config.json"
|
|
||||||
{
|
{
|
||||||
"theme": "dark",
|
"theme": "dark",
|
||||||
"logLevel": "info",
|
"logLevel": "info",
|
||||||
@ -45,21 +47,40 @@ if [ "$OPENCLAW_TYPE" = "standalone" ]; then
|
|||||||
EOF
|
EOF
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "🚀 Starting OpenClaw Gateway..."
|
# --- GATEWAY STARTUP ---
|
||||||
# We use 'gateway start' but ensure it binds to all interfaces
|
if [ "$OPENCLAW_TYPE" = "standalone" ]; then
|
||||||
# We also use --daemon=false if possible, or standard nohup
|
echo "🔧 OPENCLAW_TYPE is standalone. Starting internal Gateway..."
|
||||||
nohup openclaw gateway start > "$FOXY_HOME/logs/gateway.log" 2>&1 &
|
|
||||||
|
# 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
|
||||||
|
|
||||||
sleep 3
|
|
||||||
if pgrep -f "openclaw" > /dev/null; then
|
if pgrep -f "openclaw" > /dev/null; then
|
||||||
echo "✅ OpenClaw Gateway is UP."
|
echo "✅ OpenClaw Gateway process found (PID: $(pgrep -f "openclaw"))."
|
||||||
else
|
# Optional: check if port is listening
|
||||||
echo "❌ Gateway failed to start. Checking logs..."
|
if command -v netstat >/dev/null 2>&1; then
|
||||||
cat "$FOXY_HOME/logs/gateway.log"
|
netstat -tulpn | grep 18789 || echo "⚠️ Gateway started but port 18789 not yet listening."
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo "🔗 OPENCLAW_TYPE is shared. Host gateway expected."
|
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
|
fi
|
||||||
|
|
||||||
echo "🚀 Starting Uvicorn API Server..."
|
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
|
exec python -m uvicorn app.main:app --host 0.0.0.0 --port 7000
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user