@wendongfly/myhi 1.3.28 → 1.3.29
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 +6 -3
- package/package.json +1 -1
package/bin/daemon.js
CHANGED
|
@@ -21,6 +21,7 @@ writeFileSync(pidFile, String(process.pid));
|
|
|
21
21
|
|
|
22
22
|
let child = null;
|
|
23
23
|
let restarting = false;
|
|
24
|
+
let stopping = false;
|
|
24
25
|
let crashCount = 0;
|
|
25
26
|
let lastCrash = 0;
|
|
26
27
|
const startTime = Date.now();
|
|
@@ -46,7 +47,7 @@ function startServer() {
|
|
|
46
47
|
const thisChild = child;
|
|
47
48
|
child.on('exit', (code, signal) => {
|
|
48
49
|
if (child === thisChild) child = null; // 只清自己的引用
|
|
49
|
-
if (restarting) return; //
|
|
50
|
+
if (restarting || stopping) return; // 主动重启或正在停止,不自动恢复
|
|
50
51
|
|
|
51
52
|
// 防止崩溃循环:10秒内连续崩溃超过5次则退出
|
|
52
53
|
const now = Date.now();
|
|
@@ -113,16 +114,18 @@ function cleanup() {
|
|
|
113
114
|
// 信号处理
|
|
114
115
|
process.on('SIGTERM', () => {
|
|
115
116
|
log('收到 SIGTERM,停止...');
|
|
117
|
+
stopping = true;
|
|
116
118
|
if (child) child.kill('SIGTERM');
|
|
117
119
|
cleanup();
|
|
118
|
-
setTimeout(() => process.exit(0),
|
|
120
|
+
setTimeout(() => process.exit(0), 2000);
|
|
119
121
|
});
|
|
120
122
|
|
|
121
123
|
process.on('SIGINT', () => {
|
|
122
124
|
log('收到 SIGINT,停止...');
|
|
125
|
+
stopping = true;
|
|
123
126
|
if (child) child.kill('SIGTERM');
|
|
124
127
|
cleanup();
|
|
125
|
-
setTimeout(() => process.exit(0),
|
|
128
|
+
setTimeout(() => process.exit(0), 2000);
|
|
126
129
|
});
|
|
127
130
|
|
|
128
131
|
// Windows: 通过 stdin 消息(无 SIGUSR2 支持)
|