@wendongfly/myhi 1.3.27 → 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/bin/myhi.js +10 -3
- package/dist/index.js +1 -1
- package/dist/index.min.js +1 -1
- 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 支持)
|
package/bin/myhi.js
CHANGED
|
@@ -696,14 +696,21 @@ SSH 开发:
|
|
|
696
696
|
const port = process.env.PORT || '12300';
|
|
697
697
|
const serviceFile = '/etc/systemd/system/myhi.service';
|
|
698
698
|
|
|
699
|
+
// 找到 node 和 daemon.js 的路径,用 Type=simple 直接前台运行 daemon
|
|
700
|
+
let nodeBin;
|
|
701
|
+
try { nodeBin = ex('which node', { encoding: 'utf8' }).trim(); } catch { nodeBin = '/usr/bin/node'; }
|
|
702
|
+
// myhi bin 可能是 symlink,解析真实路径后找到同目录的 daemon.js
|
|
703
|
+
let realMyhiBin;
|
|
704
|
+
try { realMyhiBin = ex(`readlink -f ${myhiBin}`, { encoding: 'utf8' }).trim(); } catch { realMyhiBin = myhiBin; }
|
|
705
|
+
const daemonScript = join(dirname(realMyhiBin), 'daemon.js');
|
|
706
|
+
|
|
699
707
|
const unitContent = `[Unit]
|
|
700
708
|
Description=myhi - Web Terminal Sharing
|
|
701
709
|
After=network.target
|
|
702
710
|
|
|
703
711
|
[Service]
|
|
704
|
-
Type=
|
|
705
|
-
|
|
706
|
-
ExecStart=${myhiBin} -d
|
|
712
|
+
Type=simple
|
|
713
|
+
ExecStart=${nodeBin} ${daemonScript}
|
|
707
714
|
ExecStop=${myhiBin} stop
|
|
708
715
|
WorkingDirectory=${cwd}
|
|
709
716
|
Restart=on-failure
|