claw-subagent-service 0.0.140 → 0.0.141

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.
@@ -187,51 +187,70 @@ restart_docker() {
187
187
  # 如果正在运行,先停止(包括进程存在但端口未监听的情况)
188
188
  if [ -n "$pid" ] || check_port "$PORT"; then
189
189
  log_info "正在停止 OpenClaw 服务..."
190
- if [ -n "$pid" ]; then
191
- log_info "停止进程 $pid..."
192
- kill -15 "$pid" &>/dev/null || true
193
- sleep 2
194
- # 检查是否还在运行
195
- if ps -p "$pid" > /dev/null 2>&1; then
196
- log_warn "进程 $pid 仍在运行,强制停止..."
197
- kill -9 "$pid" &>/dev/null || true
198
- sleep 1
199
- fi
190
+
191
+ # 第一步:优雅停止所有 openclaw 进程
192
+ log_info "发送 SIGTERM 到所有 openclaw 进程..."
193
+ pkill -15 -f "openclaw" &>/dev/null || true
194
+ sleep 3
195
+
196
+ # 第二步:检查是否还有进程在运行
197
+ local remaining_pids=""
198
+ if command -v pgrep &>/dev/null; then
199
+ remaining_pids=$(pgrep -f "openclaw" | tr '\n' ' ')
200
+ fi
201
+
202
+ if [ -n "$remaining_pids" ]; then
203
+ log_warn "进程仍在运行: $remaining_pids,发送 SIGKILL..."
204
+ pkill -9 -f "openclaw" &>/dev/null || true
205
+ sleep 3
200
206
  fi
201
207
 
202
- # 等待停止(最多 10 秒),使用端口双重验证
208
+ # 第三步:连续监控,确保所有进程都停止(防止看门狗重启)
209
+ log_info "进入连续监控模式,确保进程完全停止..."
203
210
  local elapsed=0
204
- while [ $elapsed -lt 10 ]; do
205
- local current_pid
206
- current_pid=$(get_openclaw_pid)
207
- if [ -z "$current_pid" ] && ! check_port "$PORT"; then
208
- break
209
- fi
211
+ local consecutive_empty=0
212
+ while [ $elapsed -lt 15 ]; do
210
213
  sleep 1
211
- elapsed=$((elapsed + 1))
212
- done
213
-
214
- # 如果还在运行,强制停止并使用备选方案
215
- local current_pid_after_wait
216
- current_pid_after_wait=$(get_openclaw_pid)
217
- if [ -n "$current_pid_after_wait" ] || check_port "$PORT"; then
218
- log_warn "服务未在 10 秒内停止,正在强制停止..."
219
- if [ -n "$current_pid_after_wait" ]; then
220
- kill -9 "$current_pid_after_wait" &>/dev/null || true
221
- fi
222
- pkill -9 -f "openclaw" &>/dev/null || true
223
- if command -v fuser &>/dev/null; then
224
- fuser -k "${PORT}/tcp" &>/dev/null || true
214
+
215
+ local current_pids=""
216
+ if command -v pgrep &>/dev/null; then
217
+ current_pids=$(pgrep -f "openclaw" | tr '\n' ' ')
225
218
  fi
226
- sleep 2
227
219
 
228
- # 最终验证
229
- local final_pid
230
- final_pid=$(get_openclaw_pid)
231
- if [ -n "$final_pid" ] || check_port "$PORT"; then
232
- log_error "OpenClaw 服务停止失败!进程或端口仍在运行。"
233
- exit 1
220
+ if [ -z "$current_pids" ] && ! check_port "$PORT"; then
221
+ consecutive_empty=$((consecutive_empty + 1))
222
+ log_info "第 $elapsed 秒: 无进程且端口未监听(连续 $consecutive_empty 次)"
223
+ if [ $consecutive_empty -ge 3 ]; then
224
+ log_info "服务已完全停止"
225
+ break
226
+ fi
227
+ else
228
+ consecutive_empty=0
229
+ if [ -n "$current_pids" ]; then
230
+ log_warn "第 $elapsed 秒: 发现进程 $current_pids,再次 kill..."
231
+ pkill -9 -f "openclaw" &>/dev/null || true
232
+ fi
233
+ if check_port "$PORT"; then
234
+ log_warn "第 $elapsed 秒: 端口仍在监听,使用 fuser..."
235
+ if command -v fuser &>/dev/null; then
236
+ fuser -k "${PORT}/tcp" &>/dev/null || true
237
+ fi
238
+ fi
234
239
  fi
240
+
241
+ elapsed=$((elapsed + 1))
242
+ done
243
+
244
+ # 最终验证
245
+ local final_pids=""
246
+ if command -v pgrep &>/dev/null; then
247
+ final_pids=$(pgrep -f "openclaw" | tr '\n' ' ')
248
+ fi
249
+
250
+ if [ -n "$final_pids" ] || check_port "$PORT"; then
251
+ log_error "OpenClaw 服务停止失败!进程或端口仍在运行。"
252
+ log_error "剩余进程: $final_pids"
253
+ exit 1
235
254
  fi
236
255
 
237
256
  log_info "服务已停止"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claw-subagent-service",
3
- "version": "0.0.140",
3
+ "version": "0.0.141",
4
4
  "description": "虾说智能助手",
5
5
  "main": "cli.js",
6
6
  "bin": {