This repository has been archived by the owner on Sep 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: correct exit on 'SIGHUP', 'SIGINT' or 'SIGTERM'
- Loading branch information
Showing
12 changed files
with
79 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,27 @@ | ||
'use strict'; | ||
|
||
var QEmitter = require('qemitter'), | ||
signalHandler = new QEmitter(); | ||
const EventEmitter = require('events').EventEmitter; | ||
const Events = require('./constants/events'); | ||
const logger = require('./utils').logger; | ||
|
||
module.exports = signalHandler; | ||
const signalHandler = module.exports = new EventEmitter(); | ||
|
||
process.on('SIGHUP', notifyAndExit(1)); | ||
process.on('SIGINT', notifyAndExit(2)); | ||
process.on('SIGTERM', notifyAndExit(15)); | ||
process.on('SIGHUP', handleSignal(1)); | ||
process.on('SIGINT', handleSignal(2)); | ||
process.on('SIGTERM', handleSignal(15)); | ||
|
||
var callCount = 0; | ||
let callCount = 0; | ||
|
||
function notifyAndExit(signalNo) { | ||
var exitCode = 128 + signalNo; | ||
function handleSignal(signalNo) { | ||
const exitCode = 128 + signalNo; | ||
|
||
return function() { | ||
return () => { | ||
if (callCount++ > 0) { | ||
console.log('Force quit.'); | ||
logger.warn('Force quit.'); | ||
process.exit(exitCode); | ||
} | ||
|
||
signalHandler.emitAndWait('exit') | ||
.then(function() { | ||
console.log('Done.'); | ||
process.exit(exitCode); | ||
}) | ||
.done(); | ||
logger.warn('Cancelling...'); | ||
signalHandler.emit(Events.INTERRUPT, {exitCode}); | ||
}; | ||
} |