darkfire514 commited on
Commit
0230a18
·
verified ·
1 Parent(s): 666d2dd

Upload start.sh

Browse files
Files changed (1) hide show
  1. start.sh +35 -2
start.sh CHANGED
@@ -60,19 +60,52 @@ TTYD_PID=$!
60
 
61
  # 2. 启动 OpenClaw Gateway (本地监听 18789)
62
  echo "Starting OpenClaw Gateway..."
 
 
 
 
 
 
63
  # 确保 openclaw 在 PATH 中 (npm install -g 通常在 /usr/bin 或 /usr/local/bin)
64
  # 如果找不到,尝试使用绝对路径或 npx
65
  if command -v openclaw &> /dev/null; then
66
- openclaw gateway run &
 
 
67
  OPENCLAW_PID=$!
68
  else
69
  echo "Error: openclaw command not found! Trying to find it..."
70
  find / -name openclaw -type f 2>/dev/null
71
  echo "Trying to run via npx..."
72
- npx openclaw gateway run &
73
  OPENCLAW_PID=$!
74
  fi
75
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
  # 3. 启动 oauth2-proxy (本地监听 4180)
77
  # 回退到稳定模式:根据环境变量智能选择单个 Provider
78
  echo "Starting oauth2-proxy on 127.0.0.1:4180..."
 
60
 
61
  # 2. 启动 OpenClaw Gateway (本地监听 18789)
62
  echo "Starting OpenClaw Gateway..."
63
+
64
+ # 设置 OpenClaw 环境变量
65
+ export PORT=18789
66
+ export OPENCLAW_PORT=18789
67
+ export HOST=0.0.0.0
68
+
69
  # 确保 openclaw 在 PATH 中 (npm install -g 通常在 /usr/bin 或 /usr/local/bin)
70
  # 如果找不到,尝试使用绝对路径或 npx
71
  if command -v openclaw &> /dev/null; then
72
+ # 将日志重定向到文件以便排查,同时也输出到 stdout
73
+ echo "Using openclaw command..."
74
+ openclaw gateway run > /tmp/openclaw.log 2>&1 &
75
  OPENCLAW_PID=$!
76
  else
77
  echo "Error: openclaw command not found! Trying to find it..."
78
  find / -name openclaw -type f 2>/dev/null
79
  echo "Trying to run via npx..."
80
+ npx openclaw gateway run > /tmp/openclaw.log 2>&1 &
81
  OPENCLAW_PID=$!
82
  fi
83
 
84
+ # 等待 OpenClaw 启动 (最多 30 秒)
85
+ for i in {1..30}; do
86
+ if nc -z 127.0.0.1 18789; then
87
+ echo "OpenClaw Gateway is up and running on port 18789!"
88
+ break
89
+ fi
90
+ echo "Waiting for OpenClaw (attempt $i/30)..."
91
+
92
+ # 检查进程是否还在
93
+ if ! kill -0 $OPENCLAW_PID 2>/dev/null; then
94
+ echo "CRITICAL: OpenClaw process died! Printing logs:"
95
+ cat /tmp/openclaw.log
96
+ # 这里不退出,以便 ttyd 和 nginx 仍能运行,方便调试
97
+ break
98
+ fi
99
+
100
+ sleep 1
101
+ done
102
+
103
+ # 如果超时仍未启动,打印最后几行日志
104
+ if ! nc -z 127.0.0.1 18789; then
105
+ echo "WARNING: OpenClaw failed to start within 30s. Logs:"
106
+ tail -n 20 /tmp/openclaw.log
107
+ fi
108
+
109
  # 3. 启动 oauth2-proxy (本地监听 4180)
110
  # 回退到稳定模式:根据环境变量智能选择单个 Provider
111
  echo "Starting oauth2-proxy on 127.0.0.1:4180..."