claw-subagent-service 0.0.94 → 0.0.95

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.
@@ -22,10 +22,24 @@ MAX_WAIT=300 # 最长等待5分钟
22
22
  PORT="18789"
23
23
 
24
24
  # 检测是否在 Docker 环境(无 systemd)
25
+ # 注意:某些 Docker 镜像安装了 systemctl 命令但无法使用
26
+ # 所以同时检查 systemd 是否实际运行
25
27
  is_docker() {
28
+ # 方法1: 检查 systemctl 是否可用
26
29
  if ! command -v systemctl &>/dev/null; then
27
30
  return 0 # 无 systemctl,认为是 Docker
28
31
  fi
32
+
33
+ # 方法2: 即使安装了 systemctl,检查 systemd 是否实际运行
34
+ if [ ! -d "/run/systemd/system" ] && [ ! -d "/sys/fs/cgroup/systemd" ]; then
35
+ return 0 # systemd 未运行,认为是 Docker
36
+ fi
37
+
38
+ # 方法3: 尝试执行 systemctl status,如果失败则认为是 Docker
39
+ if ! systemctl status &>/dev/null; then
40
+ return 0 # systemctl 无法使用,认为是 Docker
41
+ fi
42
+
29
43
  return 1
30
44
  }
31
45
 
@@ -112,6 +126,7 @@ get_openclaw_pid() {
112
126
  }
113
127
 
114
128
  # 检查端口是否监听
129
+ # 注意:只检查端口,不检查进程。进程存在不等于端口在监听。
115
130
  check_port() {
116
131
  local port=$1
117
132
  if command -v ss &>/dev/null; then
@@ -126,11 +141,9 @@ check_port() {
126
141
  elif command -v fuser &>/dev/null; then
127
142
  fuser $port/tcp 2>/dev/null | grep -q '[0-9]'
128
143
  return $?
129
- else
130
- # 降级:直接检查进程
131
- [ -n "$(get_openclaw_pid)" ]
132
- return $?
133
144
  fi
145
+ # 如果所有工具都不可用,无法准确检查端口,保守返回 1(端口未监听)
146
+ return 1
134
147
  }
135
148
 
136
149
  # 等待端口启动
@@ -22,10 +22,24 @@ MAX_WAIT=300 # 最长等待5分钟
22
22
  PORT="18789"
23
23
 
24
24
  # 检测是否在 Docker 环境(无 systemd)
25
+ # 注意:某些 Docker 镜像安装了 systemctl 命令但无法使用
26
+ # 所以同时检查 systemd 是否实际运行
25
27
  is_docker() {
28
+ # 方法1: 检查 systemctl 是否可用
26
29
  if ! command -v systemctl &>/dev/null; then
27
30
  return 0 # 无 systemctl,认为是 Docker
28
31
  fi
32
+
33
+ # 方法2: 即使安装了 systemctl,检查 systemd 是否实际运行
34
+ if [ ! -d "/run/systemd/system" ] && [ ! -d "/sys/fs/cgroup/systemd" ]; then
35
+ return 0 # systemd 未运行,认为是 Docker
36
+ fi
37
+
38
+ # 方法3: 尝试执行 systemctl status,如果失败则认为是 Docker
39
+ if ! systemctl status &>/dev/null; then
40
+ return 0 # systemctl 无法使用,认为是 Docker
41
+ fi
42
+
29
43
  return 1
30
44
  }
31
45
 
@@ -112,6 +126,7 @@ get_openclaw_pid() {
112
126
  }
113
127
 
114
128
  # 检查端口是否监听
129
+ # 注意:只检查端口,不检查进程。进程存在不等于端口在监听。
115
130
  check_port() {
116
131
  local port=$1
117
132
  if command -v ss &>/dev/null; then
@@ -126,11 +141,9 @@ check_port() {
126
141
  elif command -v fuser &>/dev/null; then
127
142
  fuser $port/tcp 2>/dev/null | grep -q '[0-9]'
128
143
  return $?
129
- else
130
- # 降级:直接检查进程
131
- [ -n "$(get_openclaw_pid)" ]
132
- return $?
133
144
  fi
145
+ # 如果所有工具都不可用,无法准确检查端口,保守返回 1(端口未监听)
146
+ return 1
134
147
  }
135
148
 
136
149
  # 等待端口启动
@@ -36,10 +36,24 @@ SERVICE_NAME="openclaw-gateway.service"
36
36
  PORT="18789"
37
37
 
38
38
  # 检测是否在 Docker 环境(无 systemd)
39
+ # 注意:某些 Docker 镜像安装了 systemctl 命令但无法使用
40
+ # 所以同时检查 systemd 是否实际运行
39
41
  is_docker() {
42
+ # 方法1: 检查 systemctl 是否可用
40
43
  if ! command -v systemctl &>/dev/null; then
41
44
  return 0 # 无 systemctl,认为是 Docker
42
45
  fi
46
+
47
+ # 方法2: 即使安装了 systemctl,检查 systemd 是否实际运行
48
+ if [ ! -d "/run/systemd/system" ] && [ ! -d "/sys/fs/cgroup/systemd" ]; then
49
+ return 0 # systemd 未运行,认为是 Docker
50
+ fi
51
+
52
+ # 方法3: 尝试执行 systemctl status,如果失败则认为是 Docker
53
+ if ! systemctl status &>/dev/null; then
54
+ return 0 # systemctl 无法使用,认为是 Docker
55
+ fi
56
+
43
57
  return 1
44
58
  }
45
59
 
@@ -126,6 +140,7 @@ get_openclaw_pid() {
126
140
  }
127
141
 
128
142
  # 检查端口是否监听
143
+ # 注意:只检查端口,不检查进程。进程存在不等于端口在监听。
129
144
  check_port() {
130
145
  local port=$1
131
146
  if command -v ss &>/dev/null; then
@@ -140,11 +155,9 @@ check_port() {
140
155
  elif command -v fuser &>/dev/null; then
141
156
  fuser $port/tcp 2>/dev/null | grep -q '[0-9]'
142
157
  return $?
143
- else
144
- # 降级:直接检查进程
145
- [ -n "$(get_openclaw_pid)" ]
146
- return $?
147
158
  fi
159
+ # 如果所有工具都不可用,无法准确检查端口,保守返回 1(端口未监听)
160
+ return 1
148
161
  }
149
162
 
150
163
  # Docker 模式:查看状态
@@ -30,10 +30,25 @@ log_error() {
30
30
  SERVICE_NAME="openclaw-gateway.service"
31
31
 
32
32
  # 检测是否在 Docker 环境(无 systemd)
33
+ # 注意:某些 Docker 镜像安装了 systemctl 命令但无法使用
34
+ # 所以同时检查 systemd 是否实际运行
33
35
  is_docker() {
36
+ # 方法1: 检查 systemctl 是否可用
34
37
  if ! command -v systemctl &>/dev/null; then
35
38
  return 0 # 无 systemctl,认为是 Docker
36
39
  fi
40
+
41
+ # 方法2: 即使安装了 systemctl,检查 systemd 是否实际运行
42
+ # 在 Docker 中,/run/systemd/system 通常不存在
43
+ if [ ! -d "/run/systemd/system" ] && [ ! -d "/sys/fs/cgroup/systemd" ]; then
44
+ return 0 # systemd 未运行,认为是 Docker
45
+ fi
46
+
47
+ # 方法3: 尝试执行 systemctl status,如果失败则认为是 Docker
48
+ if ! systemctl status &>/dev/null; then
49
+ return 0 # systemctl 无法使用,认为是 Docker
50
+ fi
51
+
37
52
  return 1
38
53
  }
39
54
 
@@ -41,6 +56,7 @@ is_docker() {
41
56
  PORT="18789"
42
57
 
43
58
  # 检查端口是否监听
59
+ # 注意:只检查端口,不检查进程。进程存在不等于端口在监听。
44
60
  check_port() {
45
61
  local port=$1
46
62
  if command -v ss &>/dev/null; then
@@ -55,11 +71,9 @@ check_port() {
55
71
  elif command -v fuser &>/dev/null; then
56
72
  fuser $port/tcp 2>/dev/null | grep -q '[0-9]'
57
73
  return $?
58
- else
59
- # 最后降级:直接检查进程
60
- [ -n "$(get_openclaw_pid)" ]
61
- return $?
62
74
  fi
75
+ # 如果所有工具都不可用,无法准确检查端口,保守返回 1(端口未监听)
76
+ return 1
63
77
  }
64
78
 
65
79
  # 获取 openclaw 进程 PID
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claw-subagent-service",
3
- "version": "0.0.94",
3
+ "version": "0.0.95",
4
4
  "description": "虾说智能助手",
5
5
  "main": "cli.js",
6
6
  "bin": {
@@ -314,9 +314,12 @@ class ScriptExecutor {
314
314
  if (upper.includes(kw.toUpperCase())) return true;
315
315
  }
316
316
 
317
- // 对于 START 命令,不提前返回,让脚本完整执行
318
- // 因为 start.bat 有等待循环,需要完整输出才能判断状态
319
- if (command === OpenClawCommandEnum.START) {
317
+ // 对于 START/STOP/RESTART 命令,不提前返回
318
+ // 让脚本完整执行到 exit,由 exit code 判断成功失败
319
+ // 提前返回可能导致 kill 命令未执行完成
320
+ if (command === OpenClawCommandEnum.START ||
321
+ command === OpenClawCommandEnum.STOP ||
322
+ command === OpenClawCommandEnum.RESTART) {
320
323
  return false;
321
324
  }
322
325