Skip to content

Commit 28ec0e5

Browse files
author
Nicolas Huray
committed
Handle properly SINGINT and SIGTERM signals
1 parent c7a2470 commit 28ec0e5

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

cli.js

+13
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,16 @@ var server = require('./index.js')(argv).listen(argv.port || 4567, function() {
2727
var address = server.address(), protocol = argv.ssl ? 'https' : 'http'
2828
console.log('Listening at %s://%s:%s', protocol, address.address, address.port)
2929
})
30+
31+
// Handle signals properly
32+
// see: https://github.com/nodejs/node-v0.x-archive/issues/9131
33+
exitOnSignal('SIGINT');
34+
exitOnSignal('SIGTERM');
35+
36+
function exitOnSignal(signal) {
37+
process.on(signal, function() {
38+
console.log('\ncaught ' + signal + ', exiting');
39+
// perform all required cleanup
40+
process.exit(1);
41+
});
42+
}

0 commit comments

Comments
 (0)