claw-subagent-service 0.0.93 → 0.0.94

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.
@@ -4,7 +4,8 @@
4
4
  # 用法: ./restart.sh [选项]
5
5
  # 支持 systemd 和 Docker(无 systemd)双模式
6
6
 
7
- set -e
7
+ # 注意:不使用 set -e,因为我们已经实现了完善的错误处理和验证逻辑
8
+ # set -e 可能导致 pgrep/pidof 找不到进程时脚本意外退出
8
9
 
9
10
  # 颜色定义
10
11
  RED='\033[0;31m'
@@ -4,7 +4,8 @@
4
4
  # 用法: ./start.sh [选项]
5
5
  # 支持 systemd 和 Docker(无 systemd)双模式
6
6
 
7
- set -e
7
+ # 注意:不使用 set -e,因为我们已经实现了完善的错误处理和验证逻辑
8
+ # set -e 可能导致 pgrep/pidof 找不到进程时脚本意外退出
8
9
 
9
10
  # 颜色定义
10
11
  RED='\033[0;31m'
@@ -4,7 +4,8 @@
4
4
  # 用法: ./status.sh [选项]
5
5
  # 支持 systemd 和 Docker(无 systemd)双模式
6
6
 
7
- set -e
7
+ # 注意:不使用 set -e,因为我们已经实现了完善的错误处理和验证逻辑
8
+ # set -e 可能导致 pgrep/pidof 找不到进程时脚本意外退出
8
9
 
9
10
  # 颜色定义
10
11
  RED='\033[0;31m'
@@ -4,7 +4,8 @@
4
4
  # 用法: ./stop.sh [选项]
5
5
  # 支持 systemd 和 Docker(无 systemd)双模式
6
6
 
7
- set -e
7
+ # 注意:不使用 set -e,因为我们已经实现了完善的错误处理和验证逻辑
8
+ # set -e 可能导致 pgrep/pidof 找不到进程时脚本意外退出
8
9
 
9
10
  # 颜色定义
10
11
  RED='\033[0;31m'
@@ -146,13 +147,24 @@ get_openclaw_pid() {
146
147
 
147
148
  # Docker 模式:停止服务
148
149
  stop_docker() {
150
+ log_info "检查 OpenClaw 服务状态..."
151
+
152
+ # 获取所有 openclaw 进程 PID
153
+ local all_pids=""
154
+ if command -v pgrep &>/dev/null; then
155
+ all_pids=$(pgrep -f "openclaw" | tr '\n' ' ')
156
+ elif command -v pidof &>/dev/null; then
157
+ all_pids=$(pidof openclaw)
158
+ else
159
+ all_pids=$(ps aux | grep -v grep | grep "openclaw" | awk '{print $2}' | tr '\n' ' ')
160
+ fi
161
+
149
162
  local pid
150
163
  pid=$(get_openclaw_pid)
151
164
 
152
165
  # 检查服务状态
153
- log_info "检查 OpenClaw 服务状态..."
154
- if [ -z "$pid" ]; then
155
- # 即使找不到 PID,也检查端口是否还在监听
166
+ if [ -z "$pid" ] && [ -z "$all_pids" ]; then
167
+ # 没有进程,检查端口
156
168
  if check_port "$PORT"; then
157
169
  log_warn "端口 $PORT 仍在监听,但无法获取 PID,尝试备选停止方案..."
158
170
  # 尝试通过 fuser 直接通过端口杀进程
@@ -164,38 +176,43 @@ stop_docker() {
164
176
  # 尝试通过 pkill 停止 openclaw 相关进程
165
177
  if check_port "$PORT"; then
166
178
  log_info "使用 pkill 停止 openclaw 进程..."
167
- pkill -f "openclaw" &>/dev/null || true
179
+ pkill -9 -f "openclaw" &>/dev/null || true
168
180
  sleep 2
169
181
  fi
170
- # 最终验证
171
- if ! check_port "$PORT"; then
172
- log_info "OpenClaw 服务已停止(通过备选方案)。"
173
- log_info "服务已成功停止。"
174
- log_info "Success"
175
- exit 0
176
- else
177
- log_error "OpenClaw 服务停止失败!所有停止方案均无效。"
178
- exit 1
179
- fi
180
182
  fi
181
- log_warn "OpenClaw 服务未在运行。"
182
- exit 0
183
+
184
+ if ! check_port "$PORT" && [ -z "$(ps aux | grep -v grep | grep 'openclaw' | awk '{print $2}')" ]; then
185
+ log_warn "OpenClaw 服务未在运行。"
186
+ exit 0
187
+ else
188
+ log_error "OpenClaw 服务停止失败!"
189
+ exit 1
190
+ fi
183
191
  fi
184
192
 
185
- log_info "OpenClaw 服务正在运行(PID: $pid),准备停止..."
193
+ log_info "发现 OpenClaw 进程: $all_pids"
186
194
 
187
- # 停止服务:先发送 SIGTERM(优雅停止)
195
+ # 停止所有 openclaw 进程:先发送 SIGTERM(优雅停止)
188
196
  log_info "正在停止 OpenClaw 服务(发送 SIGTERM)..."
189
- kill "$pid" &>/dev/null || true
197
+ for p in $all_pids; do
198
+ kill "$p" &>/dev/null || true
199
+ done
190
200
 
191
- # 等待服务完全停止(最多 10 秒),使用端口双重验证
201
+ # 等待服务完全停止(最多 10 秒)
192
202
  local elapsed=0
193
203
  while [ $elapsed -lt 10 ]; do
194
- # 双重验证:检查 PID 和端口
195
- local current_pid
196
- current_pid=$(get_openclaw_pid)
197
- if [ -z "$current_pid" ] && ! check_port "$PORT"; then
198
- log_info "OpenClaw 服务停止成功!(PID 和端口均已关闭)"
204
+ # 检查是否还有 openclaw 进程
205
+ local remaining_pids=""
206
+ if command -v pgrep &>/dev/null; then
207
+ remaining_pids=$(pgrep -f "openclaw" | tr '\n' ' ')
208
+ elif command -v pidof &>/dev/null; then
209
+ remaining_pids=$(pidof openclaw)
210
+ else
211
+ remaining_pids=$(ps aux | grep -v grep | grep "openclaw" | awk '{print $2}' | tr '\n' ' ')
212
+ fi
213
+
214
+ if [ -z "$remaining_pids" ] && ! check_port "$PORT"; then
215
+ log_info "OpenClaw 服务停止成功!(所有进程已退出,端口已关闭)"
199
216
  log_info "服务已成功停止。"
200
217
  log_info "Success"
201
218
  exit 0
@@ -206,17 +223,24 @@ stop_docker() {
206
223
 
207
224
  # 如果还在运行,强制停止(SIGKILL)
208
225
  log_warn "服务未在 10 秒内停止,正在强制停止..."
209
- kill -9 "$pid" &>/dev/null || true
210
-
211
- # 额外:尝试 pkill 确保所有相关进程都被停止
226
+ for p in $all_pids; do
227
+ kill -9 "$p" &>/dev/null || true
228
+ done
212
229
  pkill -9 -f "openclaw" &>/dev/null || true
213
230
 
214
231
  # 等待进程消失(最多 5 秒)
215
232
  elapsed=0
216
233
  while [ $elapsed -lt 5 ]; do
217
- local current_pid
218
- current_pid=$(get_openclaw_pid)
219
- if [ -z "$current_pid" ] && ! check_port "$PORT"; then
234
+ local remaining_pids=""
235
+ if command -v pgrep &>/dev/null; then
236
+ remaining_pids=$(pgrep -f "openclaw" | tr '\n' ' ')
237
+ elif command -v pidof &>/dev/null; then
238
+ remaining_pids=$(pidof openclaw)
239
+ else
240
+ remaining_pids=$(ps aux | grep -v grep | grep "openclaw" | awk '{print $2}' | tr '\n' ' ')
241
+ fi
242
+
243
+ if [ -z "$remaining_pids" ] && ! check_port "$PORT"; then
220
244
  log_info "OpenClaw 服务已强制停止。"
221
245
  log_info "服务已成功停止。"
222
246
  log_info "Success"
@@ -227,21 +251,26 @@ stop_docker() {
227
251
  done
228
252
 
229
253
  # 最终验证
230
- local current_pid
231
- current_pid=$(get_openclaw_pid)
232
- if [ -z "$current_pid" ] && ! check_port "$PORT"; then
254
+ local remaining_pids=""
255
+ if command -v pgrep &>/dev/null; then
256
+ remaining_pids=$(pgrep -f "openclaw" | tr '\n' ' ')
257
+ elif command -v pidof &>/dev/null; then
258
+ remaining_pids=$(pidof openclaw)
259
+ else
260
+ remaining_pids=$(ps aux | grep -v grep | grep "openclaw" | awk '{print $2}' | tr '\n' ' ')
261
+ fi
262
+
263
+ if [ -z "$remaining_pids" ] && ! check_port "$PORT"; then
233
264
  log_info "OpenClaw 服务已停止。"
234
265
  log_info "服务已成功停止。"
235
266
  log_info "Success"
236
267
  exit 0
237
- elif check_port "$PORT"; then
238
- log_error "OpenClaw 服务停止失败!端口 $PORT 仍在监听。"
268
+ elif [ -n "$remaining_pids" ]; then
269
+ log_error "OpenClaw 服务停止失败!进程仍然存在: $remaining_pids"
239
270
  exit 1
240
271
  else
241
- log_info "OpenClaw 服务已停止(端口已关闭)。"
242
- log_info "服务已成功停止。"
243
- log_info "Success"
244
- exit 0
272
+ log_error "OpenClaw 服务停止失败!端口 $PORT 仍在监听。"
273
+ exit 1
245
274
  fi
246
275
  }
247
276
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claw-subagent-service",
3
- "version": "0.0.93",
3
+ "version": "0.0.94",
4
4
  "description": "虾说智能助手",
5
5
  "main": "cli.js",
6
6
  "bin": {