Skip to content

Commit

Permalink
fix: windows下没有kill用
Browse files Browse the repository at this point in the history
  • Loading branch information
bangbang93 committed Mar 26, 2024
1 parent 8d7b87d commit 4e2b7bd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
13 changes: 10 additions & 3 deletions src/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ export async function bootstrap(version: string): Promise<void> {
let stopping = false
const onStop = async (signal: NodeJS.Signals): Promise<void> => {
console.log(`got ${signal}, unregistering cluster`)
if (stopping) process.kill(process.pid, signal)
if (stopping) {
// eslint-disable-next-line n/no-process-exit
process.exit(1)
}

stopping = true
clearTimeout(checkFileInterval)
Expand All @@ -108,6 +111,10 @@ export async function bootstrap(version: string): Promise<void> {
server.close()
cluster.nginxProcess?.kill()
}
process.once('SIGTERM', () => onStop)
process.once('SIGINT', () => onStop)
process.once('SIGTERM', (signal) => {
void onStop(signal)
})
process.once('SIGINT', (signal) => {
void onStop(signal)
})
}
3 changes: 2 additions & 1 deletion src/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,8 @@ export class Cluster {
if (this.nginxProcess) {
this.nginxProcess.kill()
}
process.kill(process.pid, code)
// eslint-disable-next-line n/no-process-exit
process.exit(code)
}

private async _enable(): Promise<void> {
Expand Down

0 comments on commit 4e2b7bd

Please sign in to comment.