@wendongfly/myhi 1.3.11 → 1.3.13
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/myhi.js +40 -12
- package/dist/index.js +1 -1
- package/dist/index.min.js +99 -100
- package/package.json +1 -1
package/bin/myhi.js
CHANGED
|
@@ -41,17 +41,39 @@ function isRunning(pid) {
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
function stopDaemon() {
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
const serverPidFile = join(configDir, 'server.pid');
|
|
45
|
+
let stopped = false;
|
|
46
|
+
|
|
47
|
+
// 停止 daemon 进程
|
|
48
|
+
const daemonPid = readPid();
|
|
49
|
+
if (daemonPid && isRunning(daemonPid)) {
|
|
50
|
+
process.kill(daemonPid, 'SIGTERM');
|
|
51
|
+
try { unlinkSync(pidFile); } catch {}
|
|
52
|
+
console.log(`[myhi] 已停止 daemon (PID ${daemonPid})`);
|
|
53
|
+
stopped = true;
|
|
54
|
+
} else if (daemonPid) {
|
|
47
55
|
try { unlinkSync(pidFile); } catch {}
|
|
48
|
-
console.log('[myhi] 进程已不存在,已清理 PID 文件');
|
|
49
|
-
return false;
|
|
50
56
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
57
|
+
|
|
58
|
+
// 停止 server 进程(普通模式或残留进程)
|
|
59
|
+
try {
|
|
60
|
+
const serverPid = parseInt(readFileSync(serverPidFile, 'utf8').trim(), 10);
|
|
61
|
+
if (serverPid && isRunning(serverPid)) {
|
|
62
|
+
if (process.platform === 'win32') {
|
|
63
|
+
try { require('child_process').execSync(`taskkill /PID ${serverPid} /F /T`, { stdio: 'pipe', timeout: 5000 }); } catch {}
|
|
64
|
+
} else {
|
|
65
|
+
process.kill(serverPid, 'SIGTERM');
|
|
66
|
+
}
|
|
67
|
+
try { unlinkSync(serverPidFile); } catch {}
|
|
68
|
+
console.log(`[myhi] 已停止 server (PID ${serverPid})`);
|
|
69
|
+
stopped = true;
|
|
70
|
+
} else if (serverPid) {
|
|
71
|
+
try { unlinkSync(serverPidFile); } catch {}
|
|
72
|
+
}
|
|
73
|
+
} catch {}
|
|
74
|
+
|
|
75
|
+
if (!stopped) console.log('[myhi] 没有正在运行的 myhi 进程');
|
|
76
|
+
return stopped;
|
|
55
77
|
}
|
|
56
78
|
|
|
57
79
|
function startDaemon() {
|
|
@@ -113,9 +135,15 @@ if (cmd === 'attach') {
|
|
|
113
135
|
|
|
114
136
|
} else if (cmd === 'status') {
|
|
115
137
|
const pkgVersion = JSON.parse(readFileSync(join(dirname(fileURLToPath(import.meta.url)), '../package.json'), 'utf8')).version;
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
|
|
138
|
+
const daemonPid = readPid();
|
|
139
|
+
let serverPid = null;
|
|
140
|
+
try { serverPid = parseInt(readFileSync(join(configDir, 'server.pid'), 'utf8').trim(), 10); } catch {}
|
|
141
|
+
const daemonAlive = daemonPid && isRunning(daemonPid);
|
|
142
|
+
const serverAlive = serverPid && isRunning(serverPid);
|
|
143
|
+
if (daemonAlive || serverAlive) {
|
|
144
|
+
const mode = daemonAlive ? 'daemon' : '前台';
|
|
145
|
+
const pid = daemonAlive ? daemonPid : serverPid;
|
|
146
|
+
console.log(`[myhi] v${pkgVersion} 运行中 (${mode}, PID ${pid})`);
|
|
119
147
|
} else {
|
|
120
148
|
console.log(`[myhi] v${pkgVersion} 未运行`);
|
|
121
149
|
}
|