darkfire514 commited on
Commit
9790f1b
·
verified ·
1 Parent(s): 0230a18

Upload start.sh

Browse files
Files changed (1) hide show
  1. start.sh +22 -18
start.sh CHANGED
@@ -64,48 +64,52 @@ echo "Starting OpenClaw Gateway..."
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..."
 
64
  # 设置 OpenClaw 环境变量
65
  export PORT=18789
66
  export OPENCLAW_PORT=18789
67
+ export HOST=127.0.0.1
68
+ export OPENCLAW_NON_INTERACTIVE=true
69
 
70
+ # 打印当前安装的 OpenClaw 版本
71
+ openclaw --version || echo "Cannot get openclaw version"
72
+
73
+ # 启动 OpenClaw 并直接输出到控制台 (使用 tail 实时监控)
74
+ touch /tmp/openclaw.log
75
  if command -v openclaw &> /dev/null; then
76
+ echo "Executing: openclaw gateway run"
 
77
  openclaw gateway run > /tmp/openclaw.log 2>&1 &
78
  OPENCLAW_PID=$!
79
  else
80
+ echo "Executing: npx openclaw gateway run"
 
 
81
  npx openclaw gateway run > /tmp/openclaw.log 2>&1 &
82
  OPENCLAW_PID=$!
83
  fi
84
 
85
+ # 启动一个后台任务实时打印 OpenClaw 日志到控制台,方便在 HF Logs 查看
86
+ tail -f /tmp/openclaw.log &
87
+ LOG_TAIL_PID=$!
88
+
89
  # 等待 OpenClaw 启动 (最多 30 秒)
90
  for i in {1..30}; do
91
  if nc -z 127.0.0.1 18789; then
92
+ echo "SUCCESS: OpenClaw Gateway is up and running on port 18789!"
93
  break
94
  fi
95
+
96
+ # 打印当前监听的端口,看看它到底躲在哪个端口了
97
+ if [ $((i % 5)) -eq 0 ]; then
98
+ echo "Current listening ports:"
99
+ netstat -tulpn | grep LISTEN
100
+ fi
101
+
102
  echo "Waiting for OpenClaw (attempt $i/30)..."
103
 
 
104
  if ! kill -0 $OPENCLAW_PID 2>/dev/null; then
105
+ echo "CRITICAL: OpenClaw process died! Final logs:"
106
  cat /tmp/openclaw.log
 
107
  break
108
  fi
109
 
110
  sleep 1
111
  done
112
 
 
 
 
 
 
 
113
  # 3. 启动 oauth2-proxy (本地监听 4180)
114
  # 回退到稳定模式:根据环境变量智能选择单个 Provider
115
  echo "Starting oauth2-proxy on 127.0.0.1:4180..."