better signal handling.
This commit is contained in:
parent
f69c49aba1
commit
5a696ec535
@ -17,7 +17,7 @@ bitcoind.start(function(err) {
|
|||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
(function next(hash) {
|
(function next(hash) {
|
||||||
return bitcoind.getBlock(hash, function(err, block) {
|
return bitcoind.getBlock(hash, function(err, block) {
|
||||||
if (err) return console.log(err.message);
|
if (err) return print(err.message);
|
||||||
print(block);
|
print(block);
|
||||||
if (block.tx.length && block.tx[0].txid) {
|
if (block.tx.length && block.tx[0].txid) {
|
||||||
var txid = block.tx[0].txid;
|
var txid = block.tx[0].txid;
|
||||||
|
|||||||
@ -32,32 +32,26 @@ Bitcoin.prototype.start = function(callback) {
|
|||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
var none = {};
|
var none = {};
|
||||||
|
var isSignal = {};
|
||||||
|
var sigint = { name: 'SIGINT', signal: isSignal };
|
||||||
|
var sighup = { name: 'SIGHUP', signal: isSignal };
|
||||||
|
var sigquit = { name: 'SIGQUIT', signal: isSignal };
|
||||||
var exitCaught = none;
|
var exitCaught = none;
|
||||||
var errorCaught = none;
|
var errorCaught = none;
|
||||||
|
|
||||||
this.log_pipe = bitcoindjs.start(function(err, status) {
|
this.log_pipe = bitcoindjs.start(function(err, status) {
|
||||||
process.on('SIGINT', function() {
|
[sigint, sighup, sigquit].forEach(function(signal) {
|
||||||
if (process.listeners('SIGINT').length > 1) {
|
process.on(signal.name, signal.listener = function() {
|
||||||
return;
|
if (process.listeners(signal.name).length > 1) {
|
||||||
}
|
return;
|
||||||
if (!self._shutdown) {
|
}
|
||||||
process.exit(0);
|
if (!self._shutdown) {
|
||||||
} else {
|
process.exit(0);
|
||||||
self.stop();
|
} else {
|
||||||
exitCaught = 0;
|
self.stop();
|
||||||
}
|
exitCaught = signal;
|
||||||
});
|
}
|
||||||
|
});
|
||||||
process.on('SIGHUP', function() {
|
|
||||||
if (process.listeners('SIGHUP').length > 1) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!self._shutdown) {
|
|
||||||
process.exit(0);
|
|
||||||
} else {
|
|
||||||
self.stop();
|
|
||||||
exitCaught = 0;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
var exit = process.exit;
|
var exit = process.exit;
|
||||||
@ -115,6 +109,13 @@ Bitcoin.prototype.start = function(callback) {
|
|||||||
delete self._shutdown;
|
delete self._shutdown;
|
||||||
|
|
||||||
if (exitCaught !== none) {
|
if (exitCaught !== none) {
|
||||||
|
if (exitCaught.signal === isSignal) {
|
||||||
|
process.removeListener(exitCaught.name, exitCaught.listener);
|
||||||
|
setImmediate(function() {
|
||||||
|
process.kill(process.pid, exitCaught.name);
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
return self._exit(exitCaught);
|
return self._exit(exitCaught);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user