tt-help-cli-ycl 1.4.87 → 1.4.89
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/package.json +1 -1
- package/src/clash/daemon.js +11 -4
- package/src/watchdog/agent.js +17 -9
package/package.json
CHANGED
package/src/clash/daemon.js
CHANGED
|
@@ -66,10 +66,16 @@ export class ClashDaemon {
|
|
|
66
66
|
? `API 端口 ${checker.CONFIG.apiPort} 可达`
|
|
67
67
|
: `Clash 控制端口 ${checker.CONFIG.apiPort} 未开启`;
|
|
68
68
|
if (!alive) {
|
|
69
|
-
this.
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
)
|
|
69
|
+
this._waitRetry = (this._waitRetry || 0) + 1;
|
|
70
|
+
// 前 3 次(约 30s)每次打印,之后每 6 次(约 1 分钟)打印一次,避免刷屏
|
|
71
|
+
const shouldLog = this._waitRetry <= 3 || this._waitRetry % 6 === 0;
|
|
72
|
+
if (shouldLog) {
|
|
73
|
+
const waitedSec = this._waitRetry * 10;
|
|
74
|
+
this._log(`⚠ Clash 未就绪:${reason}(已等待 ${waitedSec}s)`);
|
|
75
|
+
this._log(
|
|
76
|
+
` 等待 API 端口 ${checker.CONFIG.apiPort} 可用,10s 后重试(Clash 就绪后自动接入)...`,
|
|
77
|
+
);
|
|
78
|
+
}
|
|
73
79
|
ipc.writeHealth({
|
|
74
80
|
node: "?",
|
|
75
81
|
healthy: false,
|
|
@@ -80,6 +86,7 @@ export class ClashDaemon {
|
|
|
80
86
|
this._waitTimer = setTimeout(() => this.start(), 10_000);
|
|
81
87
|
return;
|
|
82
88
|
}
|
|
89
|
+
this._waitRetry = 0; // 就绪后重置等待计数
|
|
83
90
|
// 等待期间的重试定时器已触发,清理引用
|
|
84
91
|
if (this._waitTimer) {
|
|
85
92
|
this._waitTimer = null;
|
package/src/watchdog/agent.js
CHANGED
|
@@ -499,10 +499,13 @@ export class WatchdogAgent {
|
|
|
499
499
|
console.error(`[watchdog] 宽限期结束,恢复正常心跳失败计数`);
|
|
500
500
|
}
|
|
501
501
|
|
|
502
|
+
// 看门狗作为最外层守护进程:即使服务端长时间不可达也保持运行、持续重试。
|
|
503
|
+
// 达到阈值仅提示一次并重置计数(业务进程仍由 ProcessManager 守护,服务端恢复后自动续上)
|
|
502
504
|
if (this.consecutiveFailures >= this.maxFailures) {
|
|
503
|
-
console.error(
|
|
504
|
-
|
|
505
|
-
|
|
505
|
+
console.error(
|
|
506
|
+
`[watchdog] 已连续 ${this.consecutiveFailures} 次心跳失败(服务端可能不可达),保持运行并持续重试(每 ${Math.round(this.intervalMs / 1000)}s)`,
|
|
507
|
+
);
|
|
508
|
+
this.consecutiveFailures = 0;
|
|
506
509
|
}
|
|
507
510
|
}
|
|
508
511
|
}
|
|
@@ -708,7 +711,11 @@ export class WatchdogAgent {
|
|
|
708
711
|
String(Math.max(5, Math.round(this.intervalMs / 1000))),
|
|
709
712
|
);
|
|
710
713
|
|
|
711
|
-
//
|
|
714
|
+
// 交互式终端(用户在 cmd 窗口里手动跑 tt-help watchdog):
|
|
715
|
+
// 升级重启后接管原控制台窗口继续显示(stdio inherit + 不 detached),窗口不消失
|
|
716
|
+
const interactive = !!process.stdout.isTTY;
|
|
717
|
+
|
|
718
|
+
// 非交互(计划任务/脚本/无人值守)时,新进程日志重定向到文件,崩溃有据可查
|
|
712
719
|
let logFd = undefined;
|
|
713
720
|
try {
|
|
714
721
|
const logPath = join(
|
|
@@ -723,17 +730,18 @@ export class WatchdogAgent {
|
|
|
723
730
|
let child;
|
|
724
731
|
try {
|
|
725
732
|
child = spawn(process.execPath, [cliPath, ...args], {
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
733
|
+
// 交互式:继承原 cmd 窗口一直显示;非交互:后台运行 + 日志文件
|
|
734
|
+
detached: !interactive,
|
|
735
|
+
stdio: interactive ? "inherit" : ["ignore", out, out],
|
|
736
|
+
windowsHide: !interactive, // 交互时不隐藏,保留可见窗口
|
|
729
737
|
});
|
|
730
738
|
} catch (e) {
|
|
731
739
|
console.error(`[upgrade] 重启自身失败: ${e.message},保持旧进程运行`);
|
|
732
740
|
this._recoverAfterFailedUpgrade();
|
|
733
741
|
return;
|
|
734
742
|
}
|
|
735
|
-
//
|
|
736
|
-
child.unref();
|
|
743
|
+
// 非交互后台进程独立存活(父进程退出不影响);交互式继承窗口无需 unref
|
|
744
|
+
if (!interactive) child.unref();
|
|
737
745
|
|
|
738
746
|
// 存活确认:轮询新进程是否正常存活,确认后才退出旧进程
|
|
739
747
|
let exited = false;
|