mirror of
https://github.com/hellodigua/ChatLab.git
synced 2026-10-25 17:54:34 +08:00
fix(dev): clean up web backend lifecycle
This commit is contained in:
1 parent
296573ed5c
commit
953471a514
6 files changed
+124
-106
No files matched your search
@@ -1,3 +1,5 @@
|
||||
import { spawnSync } from 'node:child_process'
|
||||
|
||||
export function createChatlabStartCommand({ serverDir, backendPort, nodeExecutable = process.execPath }) {
|
||||
return {
|
||||
command: nodeExecutable,
|
||||
@@ -16,6 +18,34 @@ export function createChatlabStartCommand({ serverDir, backendPort, nodeExecutab
|
||||
cwd: serverDir,
|
||||
stdio: ['ignore', 'pipe', 'pipe'],
|
||||
env: { ...process.env },
|
||||
detached: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
export function terminateChatlabStartProcess(
|
||||
childProcess,
|
||||
{ platform = process.platform, killProcess = process.kill, spawnSyncFn = spawnSync } = {}
|
||||
) {
|
||||
if (!childProcess) return
|
||||
if (childProcess.exitCode !== null || childProcess.signalCode !== null) return
|
||||
|
||||
const pid = childProcess.pid
|
||||
if (!pid) {
|
||||
childProcess.kill('SIGTERM')
|
||||
return
|
||||
}
|
||||
|
||||
if (platform === 'win32') {
|
||||
const result = spawnSyncFn('taskkill', ['/PID', String(pid), '/T', '/F'], { stdio: 'ignore' })
|
||||
if (result.status === 0) return
|
||||
childProcess.kill('SIGTERM')
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
killProcess(-pid, 'SIGTERM')
|
||||
} catch {
|
||||
childProcess.kill('SIGTERM')
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user