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.
- Loading branch information
Showing
24 changed files
with
535 additions
and
131 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
SIGHUP: 'SIGHUP', | ||
SIGINT: 'SIGINT', | ||
SIGTERM: 'SIGTERM' | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
EXIT: 'exit' | ||
}; |
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,38 @@ | ||
'use strict'; | ||
|
||
var QEmitter = require('qemitter'), | ||
signalHandler = new QEmitter(); | ||
const QEmitter = require('qemitter'); | ||
const SignalEvents = require('./constants/signal-events'); | ||
const SignalHandlerEvents = require('./constants/signal-handler-events'); | ||
const logger = require('./utils').logger; | ||
|
||
module.exports = signalHandler; | ||
module.exports = class SignalHandler extends QEmitter { | ||
static create() { | ||
return new SignalHandler(); | ||
} | ||
|
||
process.on('SIGHUP', notifyAndExit(1)); | ||
process.on('SIGINT', notifyAndExit(2)); | ||
process.on('SIGTERM', notifyAndExit(15)); | ||
start() { | ||
process.on(SignalEvents.SIGHUP, () => this._handleSignal(1)); | ||
process.on(SignalEvents.SIGINT, () => this._handleSignal(2)); | ||
process.on(SignalEvents.SIGTERM, () => this._handleSignal(15)); | ||
|
||
var callCount = 0; | ||
return this; | ||
} | ||
|
||
function notifyAndExit(signalNo) { | ||
var exitCode = 128 + signalNo; | ||
|
||
return function() { | ||
if (callCount++ > 0) { | ||
console.log('Force quit.'); | ||
process.exit(exitCode); | ||
_handleSignal(signalNum) { | ||
if (this._exitCode) { | ||
logger.warn('Force exit.'); | ||
process.exit(this._exitCode); | ||
} | ||
|
||
signalHandler.emitAndWait('exit') | ||
.then(function() { | ||
console.log('Done.'); | ||
process.exit(exitCode); | ||
}) | ||
.done(); | ||
}; | ||
} | ||
this._exitCode = 128 + signalNum; | ||
|
||
logger.warn('Exiting...'); | ||
return this.emitAndWait(SignalHandlerEvents.EXIT); | ||
} | ||
|
||
end() { | ||
if (this._exitCode) { | ||
process.exit(this._exitCode); | ||
} | ||
} | ||
}; |
Oops, something went wrong.