fix shutdown. sigint/sighup handlers.
This commit is contained in:
parent
7d0c31363d
commit
4410d9b9e9
@ -12,10 +12,15 @@ bitcoind.start(function(err) {
|
|||||||
bitcoind.on('open', function(status) {
|
bitcoind.on('open', function(status) {
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
var genesis = '0x000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f';
|
var genesis = '0x000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f';
|
||||||
return bitcoind.getBlock(genesis, function(err, block) {
|
(function next(hash) {
|
||||||
if (err) return console.log(err.message);
|
return bitcoind.getBlock(hash, function(err, block) {
|
||||||
print(block);
|
if (err) return console.log(err.message);
|
||||||
});
|
print(block);
|
||||||
|
if (process.argv[2] === '-r' && block.nextblockhash) {
|
||||||
|
setTimeout(next.bind(null, block.nextblockhash), 200);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})(genesis);
|
||||||
}, 1000);
|
}, 1000);
|
||||||
console.log('bitcoind: status="%s"', status);
|
console.log('bitcoind: status="%s"', status);
|
||||||
});
|
});
|
||||||
|
|||||||
@ -36,8 +36,29 @@ Bitcoin.prototype.start = function(callback) {
|
|||||||
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', self.stop.bind(self));
|
process.on('SIGINT', function() {
|
||||||
process.on('SIGHUP', self.stop.bind(self));
|
if (process.listeners('SIGINT').length > 1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!self._shutdown) {
|
||||||
|
process.exit(0);
|
||||||
|
} else {
|
||||||
|
self.stop();
|
||||||
|
exitCaught = 0;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
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;
|
||||||
self._exit = function() {
|
self._exit = function() {
|
||||||
@ -94,7 +115,7 @@ Bitcoin.prototype.start = function(callback) {
|
|||||||
delete self._shutdown;
|
delete self._shutdown;
|
||||||
|
|
||||||
if (exitCaught !== none) {
|
if (exitCaught !== none) {
|
||||||
return self._exit(0);
|
return self._exit(exitCaught);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (errorCaught !== none) {
|
if (errorCaught !== none) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user