Handle shutdown of fcoin
This commit is contained in:
parent
53511b021d
commit
59d6cc0867
@ -33,7 +33,9 @@ function main(parentServicesPath, additionalServices) {
|
|||||||
|
|
||||||
// Gracefully Shut Down
|
// Gracefully Shut Down
|
||||||
process.on('SIGTERM', function () {
|
process.on('SIGTERM', function () {
|
||||||
|
console.log("Shutting down flocore-node")
|
||||||
node.stop(function() {
|
node.stop(function() {
|
||||||
|
console.log("flocore-node successfully stopped!")
|
||||||
process.exit(0)
|
process.exit(0)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@ -201,12 +201,13 @@ function cleanShutdown(_process, node) {
|
|||||||
return _process.exit(1);
|
return _process.exit(1);
|
||||||
}
|
}
|
||||||
log.info('Halted');
|
log.info('Halted');
|
||||||
_process.exit(0);
|
process.exit(0);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function exitHandler(options, _process, node, err) {
|
function exitHandler(options, _process, node, err) {
|
||||||
if (err) {
|
// Handle and log errors other than SIGINT shutdown
|
||||||
|
if (err && err !== "SIGINT") {
|
||||||
log.error('uncaught exception:', err);
|
log.error('uncaught exception:', err);
|
||||||
if(err.stack) {
|
if(err.stack) {
|
||||||
log.error(err.stack);
|
log.error(err.stack);
|
||||||
@ -218,6 +219,7 @@ function exitHandler(options, _process, node, err) {
|
|||||||
_process.exit(-1);
|
_process.exit(-1);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
// Handle SIGINT (Ctrl+C)
|
||||||
if (options.sigint) {
|
if (options.sigint) {
|
||||||
if (!shuttingDown) {
|
if (!shuttingDown) {
|
||||||
shuttingDown = true;
|
shuttingDown = true;
|
||||||
|
|||||||
@ -3,64 +3,50 @@
|
|||||||
var index = require('../../');
|
var index = require('../../');
|
||||||
var log = index.log;
|
var log = index.log;
|
||||||
var bcoin = require('fcoin');
|
var bcoin = require('fcoin');
|
||||||
var bzmq = require('bzmq');
|
// var bzmq = require('bzmq');
|
||||||
|
|
||||||
var Bcoin = function(options) {
|
var Bcoin = function(options) {
|
||||||
this._config = this._getConfig(options);
|
this._config = this._getConfig(options);
|
||||||
};
|
};
|
||||||
|
|
||||||
Bcoin.prototype.start = function(callback) {
|
Bcoin.prototype.start = function(callback) {
|
||||||
var self = this;
|
this._bcoin = new bcoin.FullNode(this._config);
|
||||||
self._bcoin = new bcoin.FullNode(self._config);
|
|
||||||
|
|
||||||
//bcoin.set(self._config.network || 'main')
|
|
||||||
//const walletPlugin = bcoin.wallet.plugin;
|
|
||||||
|
|
||||||
// Make fcoin add the wallet plugin
|
|
||||||
//self._bcoin.use(walletPlugin)
|
|
||||||
// bzmq allows zmq connections to fcoin
|
|
||||||
//self._bcoin.use(bzmq)
|
|
||||||
//self._bzmq = self._bcoin.require('zmq')
|
|
||||||
|
|
||||||
log.info('Starting fcoin FullNode...');
|
log.info('Starting fcoin FullNode...');
|
||||||
|
|
||||||
self._bcoin.open().then(function() {
|
this._bcoin.open().then(() => {
|
||||||
|
this._bcoin.connect().then(() => {
|
||||||
// Startup the wallet plugin
|
this._bcoin.startSync();
|
||||||
//self._walletdb = self._bcoin.require('walletdb');
|
callback();
|
||||||
// self._walletdb.open().then(function() {
|
});
|
||||||
|
|
||||||
// Continue bcoin startup
|
|
||||||
self._bcoin.connect().then(function() {
|
|
||||||
log.info('Waiting for Fcoin to sync');
|
|
||||||
self._bcoin.startSync();
|
|
||||||
// this will instruct the p2p service to start trying to connect to bcoin right away
|
|
||||||
callback();
|
|
||||||
});
|
|
||||||
|
|
||||||
// })
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Bcoin.prototype.stop = function() {
|
Bcoin.prototype.stop = function(callback) {
|
||||||
this._bcoin.stopSync();
|
this._bcoin.close().then(() => {
|
||||||
this._bcoin.disconnect();
|
log.info("fcoin shutdown")
|
||||||
this._bcoin.close();
|
callback()
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// --- privates
|
// --- privates
|
||||||
|
|
||||||
Bcoin.prototype._getConfig = function(options) {
|
Bcoin.prototype._getConfig = function(options) {
|
||||||
var config = {
|
var config = {
|
||||||
checkpoints: true,
|
|
||||||
network: options.network || 'main',
|
network: options.network || 'main',
|
||||||
listen: true,
|
port: options.port,
|
||||||
|
|
||||||
|
logFile: true,
|
||||||
logConsole: true,
|
logConsole: true,
|
||||||
logLevel: 'info',
|
logLevel: 'info',
|
||||||
port: options.port,
|
|
||||||
'persistent-mempool': true,
|
indexTx: true,
|
||||||
|
indexAddress: true,
|
||||||
|
|
||||||
|
checkpoints: true,
|
||||||
|
memory: false,
|
||||||
workers: true,
|
workers: true,
|
||||||
config: true
|
listen: true
|
||||||
};
|
};
|
||||||
if (options.prefix) {
|
if (options.prefix) {
|
||||||
config.prefix = options.prefix;
|
config.prefix = options.prefix;
|
||||||
|
|||||||
@ -432,9 +432,6 @@ P2P.prototype._setResourceFilter = function(filter) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
P2P.prototype._startBcoin = function(callback) {
|
P2P.prototype._startBcoin = function(callback) {
|
||||||
|
|
||||||
var self = this;
|
|
||||||
|
|
||||||
var network;
|
var network;
|
||||||
var port;
|
var port;
|
||||||
if (['livenet', 'live', 'main', 'mainnet'].indexOf(this.node.network) !== -1) {
|
if (['livenet', 'live', 'main', 'mainnet'].indexOf(this.node.network) !== -1) {
|
||||||
@ -448,13 +445,13 @@ P2P.prototype._startBcoin = function(callback) {
|
|||||||
port = this._configPeers[0].port || 48444;
|
port = this._configPeers[0].port || 48444;
|
||||||
}
|
}
|
||||||
|
|
||||||
self._bcoin = new Bcoin({
|
this._bcoin = new Bcoin({
|
||||||
network: network,
|
network: network,
|
||||||
prefix: self.node.datadir,
|
prefix: this.node.datadir,
|
||||||
port: port
|
port: port
|
||||||
});
|
});
|
||||||
|
|
||||||
self._bcoin.start(callback);
|
this._bcoin.start(callback);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -32,7 +32,6 @@
|
|||||||
"bitcoind-rpc": "^0.7.2",
|
"bitcoind-rpc": "^0.7.2",
|
||||||
"bn.js": "^4.11.8",
|
"bn.js": "^4.11.8",
|
||||||
"body-parser": "^1.13.3",
|
"body-parser": "^1.13.3",
|
||||||
"bzmq": "^0.1.2",
|
|
||||||
"colors": "^1.1.2",
|
"colors": "^1.1.2",
|
||||||
"commander": "^2.8.1",
|
"commander": "^2.8.1",
|
||||||
"errno": "^0.1.4",
|
"errno": "^0.1.4",
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user