bitcore-node-zcash/bin/start-libbitcoind.js

62 lines
1.2 KiB
JavaScript
Raw Normal View History

2015-08-04 11:17:04 -07:00
#!/usr/bin/env node
'use strict';
2015-08-31 06:00:00 -07:00
var index = require('..');
var log = index.log;
2015-08-04 11:17:04 -07:00
process.title = 'libbitcoind';
/**
* daemon
*/
2015-08-31 06:00:00 -07:00
var daemon = require('../').services.Bitcoin({
2015-08-31 06:00:00 -07:00
node: {
datadir: process.env.BITCORENODE_DIR || process.env.HOME + '/.bitcoin',
network: {
name: process.env.BITCORENODE_NETWORK || 'livenet'
}
}
2015-08-04 11:17:04 -07:00
});
2015-08-24 07:13:45 -07:00
daemon.start(function() {
2015-08-04 11:17:04 -07:00
log.info('ready');
});
daemon.on('error', function(err) {
log.info('error="%s"', err.message);
});
daemon.on('open', function(status) {
log.info('status="%s"', status);
});
2015-08-24 07:13:45 -07:00
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
2015-08-31 06:00:00 -07:00
process.on('SIGINT', exitHandler.bind(null, {sigint:true}));