add ctrl-c behavior to daemon
This commit is contained in:
parent
a9e5ee6f1a
commit
db65d6476f
@ -15,7 +15,7 @@ var daemon = require('../').daemon({
|
||||
network: process.env.BITCORENODE_NETWORK || 'livenet'
|
||||
});
|
||||
|
||||
daemon.on('ready', function() {
|
||||
daemon.start(function() {
|
||||
log.info('ready');
|
||||
});
|
||||
|
||||
@ -26,3 +26,32 @@ daemon.on('error', function(err) {
|
||||
daemon.on('open', function(status) {
|
||||
log.info('status="%s"', status);
|
||||
});
|
||||
|
||||
function exitHandler(options, err) {
|
||||
log.info('Stopping daemon');
|
||||
if (err) {
|
||||
log.error('uncaught exception:', err);
|
||||
if(err.stack) {
|
||||
console.log(err.stack);
|
||||
}
|
||||
process.exit(-1);
|
||||
}
|
||||
if (options.sigint) {
|
||||
daemon.stop(function(err) {
|
||||
if(err) {
|
||||
log.error('Failed to stop services: ' + err);
|
||||
return process.exit(1);
|
||||
}
|
||||
|
||||
log.info('Halted');
|
||||
process.exit(0);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
//catches uncaught exceptions
|
||||
|
||||
|
||||
process.on('uncaughtException', exitHandler.bind(null, {exit:true}));
|
||||
//catches ctrl+c event
|
||||
process.on('SIGINT', exitHandler.bind(null, {sigint:true}));
|
||||
@ -172,5 +172,4 @@ function exitHandler(options, err) {
|
||||
|
||||
process.on('uncaughtException', exitHandler.bind(null, {exit:true}));
|
||||
//catches ctrl+c event
|
||||
process.on('exit', exitHandler.bind(null, {exit: true}));
|
||||
process.on('SIGINT', exitHandler.bind(null, {sigint:true}));
|
||||
|
||||
Loading…
Reference in New Issue
Block a user