Handle shutdown of fcoin

This commit is contained in:
Sky Young 2019-07-19 17:33:19 -06:00
parent 53511b021d
commit 59d6cc0867
5 changed files with 31 additions and 45 deletions

View File

@ -33,7 +33,9 @@ function main(parentServicesPath, additionalServices) {
// Gracefully Shut Down
process.on('SIGTERM', function () {
console.log("Shutting down flocore-node")
node.stop(function() {
console.log("flocore-node successfully stopped!")
process.exit(0)
})
})

View File

@ -201,12 +201,13 @@ function cleanShutdown(_process, node) {
return _process.exit(1);
}
log.info('Halted');
_process.exit(0);
process.exit(0);
});
}
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);
if(err.stack) {
log.error(err.stack);
@ -218,6 +219,7 @@ function exitHandler(options, _process, node, err) {
_process.exit(-1);
});
}
// Handle SIGINT (Ctrl+C)
if (options.sigint) {
if (!shuttingDown) {
shuttingDown = true;

View File

@ -3,64 +3,50 @@
var index = require('../../');
var log = index.log;
var bcoin = require('fcoin');
var bzmq = require('bzmq');
// var bzmq = require('bzmq');
var Bcoin = function(options) {
this._config = this._getConfig(options);
};
Bcoin.prototype.start = function(callback) {
var self = this;
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')
this._bcoin = new bcoin.FullNode(this._config);
log.info('Starting fcoin FullNode...');
self._bcoin.open().then(function() {
// Startup the wallet plugin
//self._walletdb = self._bcoin.require('walletdb');
// 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();
});
// })
this._bcoin.open().then(() => {
this._bcoin.connect().then(() => {
this._bcoin.startSync();
callback();
});
});
};
Bcoin.prototype.stop = function() {
this._bcoin.stopSync();
this._bcoin.disconnect();
this._bcoin.close();
Bcoin.prototype.stop = function(callback) {
this._bcoin.close().then(() => {
log.info("fcoin shutdown")
callback()
});
};
// --- privates
Bcoin.prototype._getConfig = function(options) {
var config = {
checkpoints: true,
network: options.network || 'main',
listen: true,
port: options.port,
logFile: true,
logConsole: true,
logLevel: 'info',
port: options.port,
'persistent-mempool': true,
indexTx: true,
indexAddress: true,
checkpoints: true,
memory: false,
workers: true,
config: true
listen: true
};
if (options.prefix) {
config.prefix = options.prefix;

View File

@ -432,9 +432,6 @@ P2P.prototype._setResourceFilter = function(filter) {
};
P2P.prototype._startBcoin = function(callback) {
var self = this;
var network;
var port;
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;
}
self._bcoin = new Bcoin({
this._bcoin = new Bcoin({
network: network,
prefix: self.node.datadir,
prefix: this.node.datadir,
port: port
});
self._bcoin.start(callback);
this._bcoin.start(callback);
};

View File

@ -32,7 +32,6 @@
"bitcoind-rpc": "^0.7.2",
"bn.js": "^4.11.8",
"body-parser": "^1.13.3",
"bzmq": "^0.1.2",
"colors": "^1.1.2",
"commander": "^2.8.1",
"errno": "^0.1.4",