@wendongfly/myhi 1.0.101 → 1.0.103
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/bin/daemon.js +10 -6
- package/dist/index.js +97 -97
- package/dist/package.json +1 -1
- package/package.json +1 -1
package/bin/daemon.js
CHANGED
|
@@ -43,8 +43,9 @@ function startServer() {
|
|
|
43
43
|
else if (msg?.type === 'restart') doRestart();
|
|
44
44
|
});
|
|
45
45
|
|
|
46
|
+
const thisChild = child;
|
|
46
47
|
child.on('exit', (code, signal) => {
|
|
47
|
-
child = null;
|
|
48
|
+
if (child === thisChild) child = null; // 只清自己的引用
|
|
48
49
|
if (restarting) return; // 主动重启,不自动恢复
|
|
49
50
|
|
|
50
51
|
// 防止崩溃循环:10秒内连续崩溃超过5次则退出
|
|
@@ -68,15 +69,18 @@ function doRestart() {
|
|
|
68
69
|
log('收到重启请求');
|
|
69
70
|
restarting = true;
|
|
70
71
|
if (child) {
|
|
71
|
-
child
|
|
72
|
-
//
|
|
73
|
-
|
|
72
|
+
const oldChild = child;
|
|
73
|
+
child = null; // 清引用,防止 startServer 里的 exit handler 再次触发
|
|
74
|
+
// 等旧进程退出后启动新的
|
|
75
|
+
const onExit = () => {
|
|
74
76
|
restarting = false;
|
|
75
77
|
setTimeout(startServer, 500);
|
|
76
|
-
}
|
|
78
|
+
};
|
|
79
|
+
oldChild.once('exit', onExit);
|
|
80
|
+
oldChild.kill('SIGTERM');
|
|
77
81
|
// 5秒后强制杀
|
|
78
82
|
setTimeout(() => {
|
|
79
|
-
|
|
83
|
+
try { oldChild.kill('SIGKILL'); } catch {}
|
|
80
84
|
}, 5000);
|
|
81
85
|
} else {
|
|
82
86
|
restarting = false;
|