mihomo-cli 4.7.2 → 4.7.4
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.
- package/CHANGELOG.md +42 -0
- package/README.md +5 -2
- package/dist/index.js +73 -39
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,47 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [4.7.4] - 2026-09-06
|
|
4
|
+
|
|
5
|
+
独立复审一轮,聚焦「上轮文档未覆盖」的缺口。两处并发/可见性缺陷均已实测复现后修复。单测 290(+7)。
|
|
6
|
+
|
|
7
|
+
### 修复
|
|
8
|
+
|
|
9
|
+
- **`start`/`install` 报「退出码 null」,信号死亡的死因在启动路径上不可见**:v4.7.3 补信号判据时把 status/doctor 的重复判断收口成 `describeAbnormalExit`,**却漏了 `runtime.assertServiceHealthy` 这第三个消费者**——它仍自己拼 `退出码 ${exitCode}`,而信号死亡时 launchd 不写 `last exit code`(整行消失,本轮用一次性 label + 桩内核再次实测确认),于是 `start` 期间被 OOM killer 杀掉的内核只显示「内核启动后立即退出(退出码 null)」,`ServiceHealth.terminatingSignal` 一路传过来却无人读。判据现收口成 `describeExitCause(exitCode, signal)` **一份**,三个消费者共用(`isCrashed` 判有无、`describeAbnormalExit` 供 status/doctor、`assertServiceHealthy` 供 start/install),修复后文案为「被信号终止(Killed: 9)」。**教训**:把实测事实锚在注释里挡不住漏铺——注释锚在事实发生处,防线要铺在所有消费处,两者不重合时只有「判据收成一个函数」才真的有效
|
|
10
|
+
- **`service.lock` 放在会被整体删除的 `runtime/` 下,跨进程互斥可被打破**:`stop()` 的 `clearRuntime()` 与 `reset runtime` 都会 `rmrf(DIRS.runtime)`,把**别的进程正持着的锁文件**一起删掉——第三个进程随即 `openSync(..., 'wx')` 成功,两个进程同时进入临界区(已实测复现)。`withFileLock` 的 token 所有权校验对此无效:它防的是「被强夺者误删新持有者的锁」,而这里锁是被第三方连目录一起删的,持锁方毫不知情。可达路径正是文档反复强调的那个——慢速 `start`(订阅更新约 10s)持锁期间另一终端 `stop`,后果是自启位终态与用户最后一条命令相反。锁现移到 `USER_DATA_DIR` 根下
|
|
11
|
+
|
|
12
|
+
### 测试
|
|
13
|
+
|
|
14
|
+
- 新增 `describeExitCause` 判据本身的用例(5 例),含「不能退化成只看退出码」的锁定断言——直接对判据断言而非各消费者,避免再出现「收口了却漏一个消费者」
|
|
15
|
+
- 新增锁存放位置的用例(2 例):断言的是**不变量**「`service.lock` 不在任何会被 `rmrf` 的目录下」而非具体路径(后者会在目录结构调整时误报),另一例记录缺陷机制本身。已验证该测试对旧位置确实失败
|
|
16
|
+
|
|
17
|
+
### 变更
|
|
18
|
+
|
|
19
|
+
- **`CLAUDE.md` 修正一处写反的记载**:「内核下载的来源信任」的 quickstart.sh 对照表里写「无标准版资产时回退第一个匹配项(CLI 不回退)」,但 `kernel.ts` 是 `standardAsset || matchingAssets[0]`,且 `kernel.spec.ts` 有单测锁定回退行为——两侧其实一致,是文档写反了。这段文字的用途正是两侧对齐的对照表,写反会误导下次对齐。顺带指明真正不回退的是 `pickLatestRelease`(全预发布时抛错)
|
|
20
|
+
- **`CLAUDE.md` 新增两条纪律**:锁文件不能放在会被 `rmrf` 的目录里(附受影响目录清单);异常退出判据只有 `describeExitCause` 一份,别散写 `lastExitCode !== 0` 也别自己拼退出码文案
|
|
21
|
+
- 去掉 4 处对同步函数(`bootoutService` / `withFileLock`)的 `await`——`withFileLock` 明确要求 `fn` 同步(持锁期间让出事件循环等于没锁),`await` 会暗示可传 async mutator
|
|
22
|
+
- README 同步两处:`start` 失败报错会写明死因(与 `status` 同口径);数据目录树补上 `service.lock` 并注明为何放在根下
|
|
23
|
+
|
|
24
|
+
## [4.7.3] - 2026-09-06
|
|
25
|
+
|
|
26
|
+
清掉 CODE_REVIEW 积压的全部未处理项(一条修复、一条决策豁免)。单测 283(+37)。
|
|
27
|
+
|
|
28
|
+
### 修复
|
|
29
|
+
|
|
30
|
+
- **TUN 模式下 `dns.enable: false` 生成自相矛盾的配置**:订阅/覆写显式关闭 DNS 时,生成的配置一边写 `dns: {enable: false}`、一边保留 `tun.dns-hijack: [any:53, tcp://any:53]`,还往已关闭的 dns 块里补注 fake-ip 字段。TUN 劫持 53 端口而内置 DNS 关着,没有任何组件接管,网络直接不可用。现把 `dns.enable` 视为 TUN 下的系统锁定项(与 `external-controller`/`mixed-port` 同一性质)强制为 `true` 并给出告警。不选「拒绝启动」是因为该值常由机场下发、用户改不了,硬拒绝等于逼用户先学会写覆写文件才能用 TUN;**只锁 `enable` 一个键**,`nameserver`/`enhanced-mode` 等仍尊重用户配置
|
|
31
|
+
- **信号死亡的内核对 `status`/`doctor` 完全不可见**:被 OOM killer 或 `kill -9` 干掉时,launchd 只写 `last terminating signal = Killed: 9`,`last exit code` 整行消失(实测 macOS 26.6,两字段互斥)——而解析器只读退出码,于是用户看到「不在运行」却没有任何异常提示,实际 KeepAlive 正每隔约 10s 反复拉起。现 `parseServicePrint` 解析该字段,崩溃判据两者取一。顺带把 status/doctor 里三处重复的「上次异常退出」判断收口成 `describeAbnormalExit`——此前补一条判据要同步改三处
|
|
32
|
+
- **`dns` 形态校验只有 TUN 一条路径有**:mixed 下 `dns: true` 一类订阅笔误照样抛裸 `TypeError` + 堆栈,被当成程序 bug。校验下沉为 `assertDnsShape`,两条路径共用
|
|
33
|
+
- **全是预发布版时 `pickLatestRelease` 回退首个 release**:会把 alpha 当稳定版装上。今日不可达(上游同时只挂一条 alpha),但内核以 root 身份跑(TUN)或长期常驻,静默降级到未发布版本不可接受,现直接抛错
|
|
34
|
+
|
|
35
|
+
### 测试
|
|
36
|
+
|
|
37
|
+
- **新增 `process-stop.spec.ts`(12 例)**:真起桩进程、真 `pkill`,覆盖 `cleanupAll` 的单杀/批量(>3)分支、符号链与真实二进制两种命令行形态、`stop` 的 notRunning 语义、`isRunning` 的 PID 复用防线。无侵入——`MIHOMO_CLI_DIR` 指向 tmpdir 后 `MAIN_INSTANCE_PATTERN` 内嵌的绝对路径使其物理上不可能匹配到用户真在跑的内核,**该前提本身有一条用例断言着**(pattern 若改成不含绝对路径,测试当场失败而非静默扩大杀伤范围)
|
|
38
|
+
- 新增 `config-dns.spec.ts`(15 例)锁定 TUN dns 锁定语义与两条路径的形态校验;`service.spec.ts` 补信号死亡的真实 launchctl 输出 fixture 与 `describeAbnormalExit`
|
|
39
|
+
|
|
40
|
+
### 变更
|
|
41
|
+
|
|
42
|
+
- **`CODE_REVIEW.md` 未处理项清空至一条**(剩「观察窗之后才崩溃的内核判不出来」,属有意边界)。sudo 路径与 launchd 端到端测试**升格为显式决策豁免**并写明理由:前者要么配免密 sudoers、要么改系统路由表、要么留 root 残留;后者一旦覆盖 `enable`/`disable` 就会在系统 disabled 表留下 launchctl 无法清除的永久记录。下轮审查不要当作覆盖率缺口重新捡起
|
|
43
|
+
- **README 同步两处用户可见行为**:TUN 章节说明 DNS 恒为开启(含只锁 `enable`、Mixed 不受影响);故障排查章节说明「上次异常退出」提示会区分 `退出码 N` 与 `被信号终止(Killed: 9)`
|
|
44
|
+
|
|
3
45
|
## [4.7.2] - 2026-09-06
|
|
4
46
|
|
|
5
47
|
文档修正,无功能变更。单测 246。
|
package/README.md
CHANGED
|
@@ -285,6 +285,8 @@ mihomo start # 恢复服务
|
|
|
285
285
|
|
|
286
286
|
TUN 用完后 `mihomo start` 会按 Mixed 重建配置并恢复自启。
|
|
287
287
|
|
|
288
|
+
**TUN 下 DNS 恒为开启**。若订阅或覆写里写了 `dns.enable: false`,TUN 模式会强制改回 `true` 并提示一行「自动修复」——TUN 会劫持 53 端口流量(`dns-hijack`),内置 DNS 关着就没有任何组件接管,网络直接不可用。只锁 `enable` 这一个键,`nameserver`、`enhanced-mode` 等仍按你的配置走。Mixed 模式不受影响,那里关 DNS 是合法配置。
|
|
289
|
+
|
|
288
290
|
### 不要用 sudo 运行
|
|
289
291
|
|
|
290
292
|
`sudo mihomo …` 会被直接拒绝。服务是用户级 LaunchAgent(域 `gui/<uid>`),以 root 运行时域变成 `gui/0` —— 一个不存在的域,所有服务操作都会静默跳过却报成功。TUN 需要的 root 权限由 CLI 内部按需申请,无需在外层加 `sudo`。
|
|
@@ -375,6 +377,7 @@ mihomo start --update-timeout=30000 # 长选项 + 等号
|
|
|
375
377
|
```
|
|
376
378
|
~/.mihomo-cli/
|
|
377
379
|
├── settings.json # 用户设置(订阅列表、当前订阅、覆写开关、端口覆盖等)
|
|
380
|
+
├── service.lock # 服务启停的跨进程锁(刻意放在根下:runtime/ 会被 stop 整体清除)
|
|
378
381
|
├── overwrite.yaml # 覆写配置(主文件,可选)
|
|
379
382
|
├── overwrite.*.yaml # 覆写配置(扩展文件,如 overwrite.dns.yaml)
|
|
380
383
|
├── subscriptions/
|
|
@@ -531,14 +534,14 @@ mihomo doctor
|
|
|
531
534
|
|
|
532
535
|
### 启动失败
|
|
533
536
|
|
|
534
|
-
`mihomo start` 会确认内核真的跑起来了才报「已启动」——内核因配置问题启动后立即退出时,命令会报错并直接附上日志尾部,退出码非 0
|
|
537
|
+
`mihomo start` 会确认内核真的跑起来了才报「已启动」——内核因配置问题启动后立即退出时,命令会报错并直接附上日志尾部,退出码非 0。常见原因是端口被占用或订阅里有内核不接受的字段。报错会写明死因,与下面 `status` 的提示同口径(`退出码 N` 或 `被信号终止(Killed: 9)`)。
|
|
535
538
|
|
|
536
539
|
```bash
|
|
537
540
|
mihomo logs 0 # 看完整原因
|
|
538
541
|
mihomo stop # 止住 launchd 的反复重试
|
|
539
542
|
```
|
|
540
543
|
|
|
541
|
-
若 `status`
|
|
544
|
+
若 `status` 显示「不在运行」但带「内核上次异常退出」的提示,说明内核正在崩溃循环中被反复拉起,同样按上面两步处理。提示会区分两种死法:`退出码 N`(内核自己退的,多为配置问题)与 `被信号终止(Killed: 9)`(被外部杀掉,常见于系统内存不足时被 OOM killer 干掉)。
|
|
542
545
|
|
|
543
546
|
### 进程无法停止
|
|
544
547
|
|
package/dist/index.js
CHANGED
|
@@ -3190,8 +3190,17 @@ var PATHS = {
|
|
|
3190
3190
|
configFile: path.join(DIRS.runtime, "config.yaml"),
|
|
3191
3191
|
logFile: path.join(DIRS.logs, "mihomo.log"),
|
|
3192
3192
|
pidFile: path.join(DIRS.runtime, "pid"),
|
|
3193
|
-
/**
|
|
3194
|
-
|
|
3193
|
+
/**
|
|
3194
|
+
* 服务操作跨进程锁:start/stop/install/uninstall 的 enable/bootstrap/bootout/disable 串行化。
|
|
3195
|
+
*
|
|
3196
|
+
* **必须放在 USER_DATA_DIR 根下,不能放 runtime/**:`stop()` 的 clearRuntime() 与
|
|
3197
|
+
* `reset runtime` 都会 `rmrf(DIRS.runtime)`,把别的进程正持着的锁文件一起删掉——
|
|
3198
|
+
* 于是第三个进程立刻 `openSync(..., 'wx')` 成功,两个进程同时进临界区(实测复现)。
|
|
3199
|
+
* withFileLock 的 token 所有权校验挡不住这种情形:它防的是「被强夺者误删新持有者的锁」,
|
|
3200
|
+
* 而这里锁是被第三方连目录一起删的,持锁方毫不知情。
|
|
3201
|
+
* 可达路径正是文档反复强调的那个:慢速 start(订阅更新约 10s)持锁期间另一终端 stop。
|
|
3202
|
+
*/
|
|
3203
|
+
serviceLock: path.join(USER_DATA_DIR, "service.lock"),
|
|
3195
3204
|
configStage1Subscription: path.join(DIRS.runtime, "1.subscription.yaml"),
|
|
3196
3205
|
configStage2Overwrite: path.join(DIRS.runtime, "2.overwrite.yaml"),
|
|
3197
3206
|
configStage3System: path.join(DIRS.runtime, "3.system.yaml"),
|
|
@@ -4223,7 +4232,17 @@ function getRuleTarget(rule) {
|
|
|
4223
4232
|
}
|
|
4224
4233
|
return last;
|
|
4225
4234
|
}
|
|
4235
|
+
function assertDnsShape(dnsRaw) {
|
|
4236
|
+
if (dnsRaw === void 0 || dnsRaw === null) return;
|
|
4237
|
+
if (typeof dnsRaw !== "object" || Array.isArray(dnsRaw)) {
|
|
4238
|
+
throw new CliError(`dns \u914D\u7F6E\u5FC5\u987B\u662F\u6620\u5C04\uFF0C\u5F53\u524D\u662F${Array.isArray(dnsRaw) ? "\u6570\u7EC4" : `\u6807\u91CF\uFF08${typeof dnsRaw}\uFF09`}`, {
|
|
4239
|
+
label: "\u914D\u7F6E\u9519\u8BEF",
|
|
4240
|
+
hint: ["dns \u662F\u8BA2\u9605/\u8986\u5199\u91CC\u7684\u5BF9\u8C61\u914D\u7F6E\u5757\uFF08enable\u3001nameserver \u7B49\uFF09\uFF0C\u4E0D\u652F\u6301\u6807\u91CF\u6216\u6570\u7EC4\u3002"]
|
|
4241
|
+
});
|
|
4242
|
+
}
|
|
4243
|
+
}
|
|
4226
4244
|
function assertConfigShape(config) {
|
|
4245
|
+
assertDnsShape(config.dns);
|
|
4227
4246
|
const listSections = [
|
|
4228
4247
|
{ key: "proxies", label: "\u8282\u70B9", needsName: true },
|
|
4229
4248
|
{ key: "proxy-groups", label: "\u4EE3\u7406\u7EC4", needsName: true },
|
|
@@ -4377,6 +4396,7 @@ function buildConfig(subRawContent, mode, scope) {
|
|
|
4377
4396
|
excludeOverwriteProxiesFromIncludeAll(withOverwrites, overwriteFiles, baseProxyNames);
|
|
4378
4397
|
}
|
|
4379
4398
|
const systemConfig = {};
|
|
4399
|
+
const lockedWarnings = [];
|
|
4380
4400
|
for (const [key, value] of Object.entries(BASE_CONFIG)) {
|
|
4381
4401
|
if (!(key in withOverwrites)) {
|
|
4382
4402
|
systemConfig[key] = value;
|
|
@@ -4398,20 +4418,16 @@ function buildConfig(subRawContent, mode, scope) {
|
|
|
4398
4418
|
}
|
|
4399
4419
|
if (mode === "tun") {
|
|
4400
4420
|
systemConfig.tun = TUN_CONFIG.tun;
|
|
4401
|
-
|
|
4402
|
-
|
|
4403
|
-
throw new CliError(`dns \u914D\u7F6E\u5FC5\u987B\u662F\u6620\u5C04\uFF0C\u5F53\u524D\u662F${Array.isArray(dnsRaw) ? "\u6570\u7EC4" : `\u6807\u91CF\uFF08${typeof dnsRaw}\uFF09`}`, {
|
|
4404
|
-
label: "\u914D\u7F6E\u9519\u8BEF",
|
|
4405
|
-
hint: ["dns \u662F\u8BA2\u9605/\u8986\u5199\u91CC\u7684\u5BF9\u8C61\u914D\u7F6E\u5757\uFF08enable\u3001nameserver \u7B49\uFF09\uFF0C\u4E0D\u652F\u6301\u6807\u91CF\u6216\u6570\u7EC4\u3002"]
|
|
4406
|
-
});
|
|
4407
|
-
}
|
|
4408
|
-
const subDns = dnsRaw || {};
|
|
4421
|
+
assertDnsShape(withOverwrites.dns);
|
|
4422
|
+
const subDns = withOverwrites.dns || {};
|
|
4409
4423
|
const dns = {};
|
|
4410
|
-
|
|
4424
|
+
const dnsExplicitlyDisabled = "enable" in subDns && subDns.enable !== true;
|
|
4425
|
+
dns.enable = true;
|
|
4411
4426
|
if (!("enhanced-mode" in subDns)) dns["enhanced-mode"] = "fake-ip";
|
|
4412
4427
|
if (!("fake-ip-range" in subDns)) dns["fake-ip-range"] = "198.18.0.1/16";
|
|
4413
|
-
|
|
4414
|
-
|
|
4428
|
+
systemConfig.dns = dns;
|
|
4429
|
+
if (dnsExplicitlyDisabled) {
|
|
4430
|
+
lockedWarnings.push("TUN \u6A21\u5F0F\u5DF2\u5F3A\u5236\u5F00\u542F DNS\uFF08\u8BA2\u9605/\u8986\u5199\u4E2D\u7684 dns.enable \u88AB\u5FFD\u7565\uFF09\uFF1ATUN \u4F1A\u52AB\u6301 53 \u7AEF\u53E3\u6D41\u91CF\uFF0C\u5185\u7F6E DNS \u5173\u95ED\u65F6\u65E0\u7EC4\u4EF6\u63A5\u7BA1\uFF0C\u7F51\u7EDC\u5C06\u4E0D\u53EF\u7528");
|
|
4415
4431
|
}
|
|
4416
4432
|
} else {
|
|
4417
4433
|
delete withOverwrites.tun;
|
|
@@ -4432,7 +4448,7 @@ function buildConfig(subRawContent, mode, scope) {
|
|
|
4432
4448
|
"skip-domain": ["+.push.apple.com"]
|
|
4433
4449
|
};
|
|
4434
4450
|
}
|
|
4435
|
-
const warnings = validateConfig(merged);
|
|
4451
|
+
const warnings = [...lockedWarnings, ...validateConfig(merged)];
|
|
4436
4452
|
return { config: merged, subscriptionConfig, overwriteFiles, systemConfig, warnings };
|
|
4437
4453
|
}
|
|
4438
4454
|
function writeMihomoConfig(configObj) {
|
|
@@ -4801,10 +4817,12 @@ function parseServicePrint(output) {
|
|
|
4801
4817
|
const pid = pidMatch ? Number.parseInt(pidMatch[1], 10) : null;
|
|
4802
4818
|
const exitMatch = output.match(/^\tlast exit code = (\d+)$/m);
|
|
4803
4819
|
const lastExitCode = exitMatch ? Number.parseInt(exitMatch[1], 10) : null;
|
|
4820
|
+
const signalMatch = output.match(/^\tlast terminating signal = (.+)$/m);
|
|
4804
4821
|
return {
|
|
4805
4822
|
state: stateMatch ? stateMatch[1].trim() : null,
|
|
4806
4823
|
pid: pid !== null && Number.isInteger(pid) && pid > 0 ? pid : null,
|
|
4807
|
-
lastExitCode: lastExitCode !== null && Number.isInteger(lastExitCode) ? lastExitCode : null
|
|
4824
|
+
lastExitCode: lastExitCode !== null && Number.isInteger(lastExitCode) ? lastExitCode : null,
|
|
4825
|
+
lastTerminatingSignal: signalMatch ? signalMatch[1].trim() : null
|
|
4808
4826
|
};
|
|
4809
4827
|
}
|
|
4810
4828
|
function parseDisabledList(output, label) {
|
|
@@ -4840,11 +4858,11 @@ function getServiceStatus() {
|
|
|
4840
4858
|
assertLaunchctlQueryOk(print.status, "print");
|
|
4841
4859
|
const loaded = print.status === 0;
|
|
4842
4860
|
if (!installed && !loaded) {
|
|
4843
|
-
return { installed: false, loaded: false, running: false, pid: null, disabled: false, lastExitCode: null };
|
|
4861
|
+
return { installed: false, loaded: false, running: false, pid: null, disabled: false, lastExitCode: null, lastTerminatingSignal: null };
|
|
4844
4862
|
}
|
|
4845
|
-
const { state, pid, lastExitCode } = loaded ? parseServicePrint(print.stdout) : { state: null, pid: null, lastExitCode: null };
|
|
4863
|
+
const { state, pid, lastExitCode, lastTerminatingSignal } = loaded ? parseServicePrint(print.stdout) : { state: null, pid: null, lastExitCode: null, lastTerminatingSignal: null };
|
|
4846
4864
|
const disabled = isServiceDisabledInLaunchd();
|
|
4847
|
-
return { installed, loaded, running: state === "running", pid, disabled, lastExitCode };
|
|
4865
|
+
return { installed, loaded, running: state === "running", pid, disabled, lastExitCode, lastTerminatingSignal };
|
|
4848
4866
|
}
|
|
4849
4867
|
async function waitServiceHealthy() {
|
|
4850
4868
|
const deadline = Date.now() + SERVICE_OBSERVE_MS;
|
|
@@ -4854,26 +4872,35 @@ async function waitServiceHealthy() {
|
|
|
4854
4872
|
await sleep(SERVICE_HEALTH_INTERVAL_MS);
|
|
4855
4873
|
last = getServiceStatus();
|
|
4856
4874
|
if (isCrashed(last)) {
|
|
4857
|
-
return { healthy: false, crashed: true, pid: null, exitCode: last.lastExitCode };
|
|
4875
|
+
return { healthy: false, crashed: true, pid: null, exitCode: last.lastExitCode, terminatingSignal: last.lastTerminatingSignal };
|
|
4858
4876
|
}
|
|
4859
4877
|
if (!last.loaded) {
|
|
4860
|
-
return { healthy: false, crashed: false, pid: null, exitCode: last.lastExitCode };
|
|
4878
|
+
return { healthy: false, crashed: false, pid: null, exitCode: last.lastExitCode, terminatingSignal: last.lastTerminatingSignal };
|
|
4861
4879
|
}
|
|
4862
4880
|
}
|
|
4863
|
-
if (last.running) return { healthy: true, crashed: false, pid: last.pid, exitCode: null };
|
|
4881
|
+
if (last.running) return { healthy: true, crashed: false, pid: last.pid, exitCode: null, terminatingSignal: null };
|
|
4864
4882
|
while (Date.now() < graceDeadline) {
|
|
4865
4883
|
await sleep(SERVICE_HEALTH_INTERVAL_MS);
|
|
4866
4884
|
last = getServiceStatus();
|
|
4867
4885
|
if (isCrashed(last)) {
|
|
4868
|
-
return { healthy: false, crashed: true, pid: null, exitCode: last.lastExitCode };
|
|
4886
|
+
return { healthy: false, crashed: true, pid: null, exitCode: last.lastExitCode, terminatingSignal: last.lastTerminatingSignal };
|
|
4869
4887
|
}
|
|
4870
4888
|
if (!last.loaded) break;
|
|
4871
|
-
if (last.running) return { healthy: true, crashed: false, pid: last.pid, exitCode: null };
|
|
4889
|
+
if (last.running) return { healthy: true, crashed: false, pid: last.pid, exitCode: null, terminatingSignal: null };
|
|
4872
4890
|
}
|
|
4873
|
-
return { healthy: false, crashed: false, pid: last.pid, exitCode: last.lastExitCode };
|
|
4891
|
+
return { healthy: false, crashed: false, pid: last.pid, exitCode: last.lastExitCode, terminatingSignal: last.lastTerminatingSignal };
|
|
4892
|
+
}
|
|
4893
|
+
function describeExitCause(exitCode, terminatingSignal) {
|
|
4894
|
+
if (terminatingSignal !== null) return `\u88AB\u4FE1\u53F7\u7EC8\u6B62\uFF08${terminatingSignal}\uFF09`;
|
|
4895
|
+
if (exitCode !== null && exitCode !== 0) return `\u9000\u51FA\u7801 ${exitCode}`;
|
|
4896
|
+
return null;
|
|
4874
4897
|
}
|
|
4875
4898
|
function isCrashed(status) {
|
|
4876
|
-
|
|
4899
|
+
if (status.running) return false;
|
|
4900
|
+
return describeExitCause(status.lastExitCode, status.lastTerminatingSignal) !== null;
|
|
4901
|
+
}
|
|
4902
|
+
function describeAbnormalExit(status) {
|
|
4903
|
+
return describeExitCause(status.lastExitCode, status.lastTerminatingSignal);
|
|
4877
4904
|
}
|
|
4878
4905
|
function escapeXml(s) {
|
|
4879
4906
|
return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
@@ -5003,7 +5030,7 @@ async function installService(wasRunning) {
|
|
|
5003
5030
|
hint: [(lint.stderr || lint.stdout || "").trim()].filter(Boolean)
|
|
5004
5031
|
});
|
|
5005
5032
|
}
|
|
5006
|
-
|
|
5033
|
+
bootoutService();
|
|
5007
5034
|
await waitUntilUnloaded();
|
|
5008
5035
|
fs8.mkdirSync(path6.dirname(PATHS.userAgentPlist), { recursive: true });
|
|
5009
5036
|
fs8.copyFileSync(stagePath, PATHS.userAgentPlist);
|
|
@@ -5045,7 +5072,7 @@ async function startService() {
|
|
|
5045
5072
|
});
|
|
5046
5073
|
}
|
|
5047
5074
|
cleanupRootResidue();
|
|
5048
|
-
|
|
5075
|
+
bootoutService();
|
|
5049
5076
|
await waitUntilUnloaded();
|
|
5050
5077
|
rotateAndCleanupLogs();
|
|
5051
5078
|
withFileLock(PATHS.serviceLock, () => {
|
|
@@ -5067,7 +5094,7 @@ function disableServiceAutoStart() {
|
|
|
5067
5094
|
}
|
|
5068
5095
|
async function stopService() {
|
|
5069
5096
|
assertServiceLabelSafe();
|
|
5070
|
-
|
|
5097
|
+
withFileLock(PATHS.serviceLock, () => {
|
|
5071
5098
|
bootoutService();
|
|
5072
5099
|
disableServiceAutoStart();
|
|
5073
5100
|
});
|
|
@@ -5076,7 +5103,7 @@ async function stopService() {
|
|
|
5076
5103
|
}
|
|
5077
5104
|
async function uninstallService() {
|
|
5078
5105
|
assertServiceLabelSafe();
|
|
5079
|
-
|
|
5106
|
+
withFileLock(PATHS.serviceLock, () => {
|
|
5080
5107
|
bootoutService();
|
|
5081
5108
|
disableServiceAutoStart();
|
|
5082
5109
|
});
|
|
@@ -5486,7 +5513,8 @@ async function assertServiceHealthy(label = "\u542F\u52A8\u5931\u8D25") {
|
|
|
5486
5513
|
const health = await waitServiceHealthy();
|
|
5487
5514
|
if (health.healthy) return health.pid;
|
|
5488
5515
|
const tail = readLogTail();
|
|
5489
|
-
const
|
|
5516
|
+
const cause = describeExitCause(health.exitCode, health.terminatingSignal);
|
|
5517
|
+
const reason = health.crashed ? `\u5185\u6838\u542F\u52A8\u540E\u7ACB\u5373\u9000\u51FA\uFF08${cause ?? "\u6B7B\u56E0\u672A\u8BB0\u5F55"}\uFF09` : "\u5185\u6838\u672A\u80FD\u8FDB\u5165\u8FD0\u884C\u72B6\u6001";
|
|
5490
5518
|
throw new CliError(reason, {
|
|
5491
5519
|
label,
|
|
5492
5520
|
hint: [
|
|
@@ -5965,6 +5993,7 @@ function buildStatusJson(args) {
|
|
|
5965
5993
|
running: args.service.running,
|
|
5966
5994
|
disabled: args.service.disabled,
|
|
5967
5995
|
lastExitCode: args.service.lastExitCode,
|
|
5996
|
+
lastTerminatingSignal: args.service.lastTerminatingSignal,
|
|
5968
5997
|
legacySystemInstall: args.legacy
|
|
5969
5998
|
}
|
|
5970
5999
|
};
|
|
@@ -6028,8 +6057,9 @@ async function printStatus(args = []) {
|
|
|
6028
6057
|
if (running && probe && !probe.ok) {
|
|
6029
6058
|
console.log(colors.yellow(` \u5F02\u5E38: ${connectivityHint(urgency)}`));
|
|
6030
6059
|
}
|
|
6031
|
-
|
|
6032
|
-
|
|
6060
|
+
const abnormalExit = describeAbnormalExit(service);
|
|
6061
|
+
if (!running && service.installed && !service.disabled && abnormalExit) {
|
|
6062
|
+
console.log(colors.yellow(` \u5F02\u5E38: \u5185\u6838\u4E0A\u6B21\u5F02\u5E38\u9000\u51FA\uFF08${abnormalExit}\uFF09\uFF0Claunchd \u6B63\u5728\u53CD\u590D\u62C9\u8D77`));
|
|
6033
6063
|
console.log(colors.gray(" \u67E5\u770B\u539F\u56E0: mihomo logs 0 \u505C\u6B62\u91CD\u8BD5: mihomo stop"));
|
|
6034
6064
|
}
|
|
6035
6065
|
const kernelVersion = getKernelVersion();
|
|
@@ -7032,14 +7062,15 @@ async function collectChecks() {
|
|
|
7032
7062
|
} else if (!service.installed) {
|
|
7033
7063
|
push("\u670D\u52A1", "fail", "plist \u4E0D\u5B58\u5728\u4F46\u4EFB\u52A1\u4ECD\u88C5\u8F7D\uFF0CKeepAlive \u4F1A\u6301\u7EED\u62C9\u8D77\u5185\u6838", "mihomo uninstall");
|
|
7034
7064
|
} else if (service.running) {
|
|
7035
|
-
const
|
|
7036
|
-
push("\u670D\u52A1", "ok", `\u8FD0\u884C\u4E2D${service.disabled ? "\uFF08\u81EA\u542F\u5DF2\u5173\u95ED\uFF09" : ""}${
|
|
7037
|
-
if (
|
|
7038
|
-
push("\u670D\u52A1\u7A33\u5B9A\u6027", "warn", `\u5185\u6838\u4E0A\u6B21\u5F02\u5E38\u9000\u51FA\uFF08
|
|
7065
|
+
const abnormalExit = describeAbnormalExit(service);
|
|
7066
|
+
push("\u670D\u52A1", "ok", `\u8FD0\u884C\u4E2D${service.disabled ? "\uFF08\u81EA\u542F\u5DF2\u5173\u95ED\uFF09" : ""}${abnormalExit ? `\uFF0C\u4E0A\u6B21\u5F02\u5E38\u9000\u51FA\uFF08${abnormalExit}\uFF09` : ""}`);
|
|
7067
|
+
if (abnormalExit) {
|
|
7068
|
+
push("\u670D\u52A1\u7A33\u5B9A\u6027", "warn", `\u5185\u6838\u4E0A\u6B21\u5F02\u5E38\u9000\u51FA\uFF08${abnormalExit}\uFF09`, "mihomo logs 0 \u67E5\u770B\u539F\u56E0");
|
|
7039
7069
|
}
|
|
7040
7070
|
} else {
|
|
7041
|
-
|
|
7042
|
-
|
|
7071
|
+
const abnormalExit = describeAbnormalExit(service);
|
|
7072
|
+
if (!service.disabled && abnormalExit) {
|
|
7073
|
+
push("\u670D\u52A1", "fail", `\u5185\u6838\u4E0A\u6B21\u5F02\u5E38\u9000\u51FA\uFF08${abnormalExit}\uFF09\uFF0Claunchd \u6B63\u5728\u53CD\u590D\u62C9\u8D77`, "mihomo logs 0 \u67E5\u770B\u539F\u56E0\uFF0Cmihomo stop \u505C\u6B62\u91CD\u8BD5");
|
|
7043
7074
|
} else {
|
|
7044
7075
|
push("\u670D\u52A1", "ok", `\u5DF2\u5B89\u88C5\uFF0C\u672A\u8FD0\u884C${service.disabled ? "\uFF08\u81EA\u542F\u5DF2\u5173\u95ED\uFF09" : ""}`);
|
|
7045
7076
|
}
|
|
@@ -7186,7 +7217,10 @@ function pickLatestRelease(releases) {
|
|
|
7186
7217
|
const stableReleases = releases.filter(
|
|
7187
7218
|
(r) => !r.prerelease && !r.tag_name.toLowerCase().includes("alpha") && !r.tag_name.toLowerCase().includes("beta") && !r.tag_name.toLowerCase().includes("prerelease")
|
|
7188
7219
|
);
|
|
7189
|
-
|
|
7220
|
+
if (stableReleases.length === 0) {
|
|
7221
|
+
throw new Error(`\u672A\u627E\u5230\u7A33\u5B9A\u7248\u5185\u6838\uFF08\u83B7\u53D6\u5230\u7684 ${releases.length} \u6761 release \u5168\u90E8\u662F\u9884\u53D1\u5E03\u7248\uFF09`);
|
|
7222
|
+
}
|
|
7223
|
+
return stableReleases[0];
|
|
7190
7224
|
}
|
|
7191
7225
|
async function getLatestRelease(repo, proxyPort) {
|
|
7192
7226
|
const url = `https://api.github.com/repos/${repo}/releases`;
|