claw-subagent-service 0.0.95 → 0.0.96

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -206,15 +206,17 @@ stop_docker() {
206
206
 
207
207
  log_info "发现 OpenClaw 进程: $all_pids"
208
208
 
209
- # 停止所有 openclaw 进程:先发送 SIGTERM(优雅停止)
210
- log_info "正在停止 OpenClaw 服务(发送 SIGTERM)..."
209
+ # 直接发送 SIGKILL(强制停止),避免 SIGTERM 被忽略
210
+ log_info "正在强制停止 OpenClaw 服务(SIGKILL)..."
211
211
  for p in $all_pids; do
212
- kill "$p" &>/dev/null || true
212
+ kill -9 "$p" 2>/dev/null || true
213
213
  done
214
+ # 额外使用 pkill 确保所有相关进程都被停止
215
+ pkill -9 -f "openclaw" 2>/dev/null || true
214
216
 
215
- # 等待服务完全停止(最多 10 秒)
217
+ # 等待进程退出(最多 3 秒)
216
218
  local elapsed=0
217
- while [ $elapsed -lt 10 ]; do
219
+ while [ $elapsed -lt 3 ]; do
218
220
  # 检查是否还有 openclaw 进程
219
221
  local remaining_pids=""
220
222
  if command -v pgrep &>/dev/null; then
@@ -225,8 +227,8 @@ stop_docker() {
225
227
  remaining_pids=$(ps aux | grep -v grep | grep "openclaw" | awk '{print $2}' | tr '\n' ' ')
226
228
  fi
227
229
 
228
- if [ -z "$remaining_pids" ] && ! check_port "$PORT"; then
229
- log_info "OpenClaw 服务停止成功!(所有进程已退出,端口已关闭)"
230
+ if [ -z "$remaining_pids" ]; then
231
+ log_info "OpenClaw 服务已停止。(所有进程已退出)"
230
232
  log_info "服务已成功停止。"
231
233
  log_info "Success"
232
234
  exit 0
@@ -235,36 +237,13 @@ stop_docker() {
235
237
  elapsed=$((elapsed + 1))
236
238
  done
237
239
 
238
- # 如果还在运行,强制停止(SIGKILL)
239
- log_warn "服务未在 10 秒内停止,正在强制停止..."
240
- for p in $all_pids; do
241
- kill -9 "$p" &>/dev/null || true
242
- done
243
- pkill -9 -f "openclaw" &>/dev/null || true
244
-
245
- # 等待进程消失(最多 5 秒)
246
- elapsed=0
247
- while [ $elapsed -lt 5 ]; do
248
- local remaining_pids=""
249
- if command -v pgrep &>/dev/null; then
250
- remaining_pids=$(pgrep -f "openclaw" | tr '\n' ' ')
251
- elif command -v pidof &>/dev/null; then
252
- remaining_pids=$(pidof openclaw)
253
- else
254
- remaining_pids=$(ps aux | grep -v grep | grep "openclaw" | awk '{print $2}' | tr '\n' ' ')
255
- fi
256
-
257
- if [ -z "$remaining_pids" ] && ! check_port "$PORT"; then
258
- log_info "OpenClaw 服务已强制停止。"
259
- log_info "服务已成功停止。"
260
- log_info "Success"
261
- exit 0
262
- fi
263
- sleep 1
264
- elapsed=$((elapsed + 1))
265
- done
240
+ # 如果进程仍在,再次强制停止
241
+ log_warn "进程仍在运行,再次强制停止..."
242
+ pkill -9 -f "openclaw" 2>/dev/null || true
243
+ killall -9 openclaw 2>/dev/null || true
266
244
 
267
- # 最终验证
245
+ # 最终检查
246
+ sleep 2
268
247
  local remaining_pids=""
269
248
  if command -v pgrep &>/dev/null; then
270
249
  remaining_pids=$(pgrep -f "openclaw" | tr '\n' ' ')
@@ -274,16 +253,13 @@ stop_docker() {
274
253
  remaining_pids=$(ps aux | grep -v grep | grep "openclaw" | awk '{print $2}' | tr '\n' ' ')
275
254
  fi
276
255
 
277
- if [ -z "$remaining_pids" ] && ! check_port "$PORT"; then
256
+ if [ -z "$remaining_pids" ]; then
278
257
  log_info "OpenClaw 服务已停止。"
279
258
  log_info "服务已成功停止。"
280
259
  log_info "Success"
281
260
  exit 0
282
- elif [ -n "$remaining_pids" ]; then
283
- log_error "OpenClaw 服务停止失败!进程仍然存在: $remaining_pids"
284
- exit 1
285
261
  else
286
- log_error "OpenClaw 服务停止失败!端口 $PORT 仍在监听。"
262
+ log_error "OpenClaw 服务停止失败!进程仍然存在: $remaining_pids"
287
263
  exit 1
288
264
  fi
289
265
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claw-subagent-service",
3
- "version": "0.0.95",
3
+ "version": "0.0.96",
4
4
  "description": "虾说智能助手",
5
5
  "main": "cli.js",
6
6
  "bin": {
@@ -136,33 +136,29 @@ async function verifyCommandResult(command, result, scriptOutput = '') {
136
136
  }
137
137
 
138
138
  if (command === OpenClawCommandEnum.STOP) {
139
- // 等待 3 秒后验证端口
140
- await new Promise(resolve => setTimeout(resolve, 3000));
141
- const portStatus = await getOpenClawStatus(18789);
142
- console.log(`[OpenClawControl] 停止后端口状态: ${portStatus}`);
139
+ // 停止命令验证:多次检查端口,处理看门狗自动重启的情况
140
+ console.log(`[OpenClawControl] 开始验证停止结果...`);
141
+
142
+ let portStatus = 1;
143
+ let checkCount = 0;
144
+ const maxChecks = 5; // 最多检查 5 次
145
+
146
+ while (checkCount < maxChecks && portStatus === 1) {
147
+ await new Promise(resolve => setTimeout(resolve, 3000)); // 每次等待 3 秒
148
+ portStatus = await getOpenClawStatus(18789);
149
+ console.log(`[OpenClawControl] 停止验证第 ${checkCount + 1} 次检查,端口状态: ${portStatus}`);
150
+ checkCount++;
151
+ }
143
152
 
144
153
  if (portStatus === 1) {
145
- // 端口仍在监听,但检查脚本是否报告已停止
146
- if (outputUpper.includes('SUCCESS') || outputUpper.includes('STOPPED')) {
147
- console.warn(`[OpenClawControl] 警告: 端口仍在监听,但脚本报告成功。可能是僵尸进程或服务未正确停止。`);
148
- // 仍然返回成功,但附带警告信息
149
- return {
150
- status: result.status,
151
- message: result.message + ' (警告: 端口仍在监听)'
152
- };
153
- }
154
+ console.error(`[OpenClawControl] 停止失败: 经过 ${maxChecks} 次检查,端口 18789 仍在监听。服务可能被看门狗自动重启。`);
154
155
  return {
155
156
  status: OpenClawServiceStatus.ERROR,
156
- message: '停止失败: 服务仍在运行'
157
- };
158
- } else if (portStatus === 2) {
159
- // 进程存在但端口未监听,可能服务正在停止中
160
- console.warn(`[OpenClawControl] 警告: openclaw 进程仍存在但端口已关闭。`);
161
- return {
162
- status: result.status,
163
- message: result.message + ' (警告: 进程仍存在)'
157
+ message: '停止失败: 服务仍在运行(可能被自动重启)'
164
158
  };
165
159
  }
160
+
161
+ console.log(`[OpenClawControl] 停止验证通过: 端口已关闭`);
166
162
  } else if (command === OpenClawCommandEnum.START || command === OpenClawCommandEnum.RESTART) {
167
163
  // 等待服务启动
168
164
  const maxWait = command === OpenClawCommandEnum.START ? 30 : 60;