itns-sidechain/bin/node

82 lines
1.6 KiB
Text
Raw Normal View History

2016-02-14 18:05:21 -08:00
#!/usr/bin/env node
2016-06-13 01:06:01 -07:00
'use strict';
2020-03-05 10:34:56 -08:00
Buffer.poolSize = 0;
2018-08-01 20:00:09 -07:00
process.title = 'hsd';
2016-07-30 13:53:43 -07:00
if (process.argv.indexOf('--help') !== -1
|| process.argv.indexOf('-h') !== -1) {
2018-09-26 17:01:40 -07:00
console.error('See the hsd docs at:');
console.error('https://handshake-org.github.io');
process.exit(1);
}
if (process.argv.indexOf('--version') !== -1
|| process.argv.indexOf('-v') !== -1) {
2017-06-29 20:54:07 -07:00
const pkg = require('../package.json');
console.log(pkg.version);
process.exit(0);
}
const FullNode = require('../lib/node/fullnode');
2016-02-14 18:05:21 -08:00
const node = new FullNode({
config: true,
argv: true,
env: true,
2016-07-04 05:36:06 -07:00
logFile: true,
2017-03-14 05:16:52 -07:00
logConsole: true,
logLevel: 'debug',
2017-12-06 17:05:00 -08:00
memory: false,
2017-07-07 08:15:10 -07:00
workers: true,
listen: false,
network: 'main',
loader: require
2016-02-14 18:05:21 -08:00
});
// Temporary hack
if (!node.config.bool('no-wallet') && !node.has('walletdb')) {
const plugin = require('../lib/wallet/plugin');
node.use(plugin);
}
2017-06-29 20:54:07 -07:00
process.on('unhandledRejection', (err, promise) => {
throw err;
2016-02-14 18:05:21 -08:00
});
2016-03-22 17:36:58 -07:00
process.on('SIGINT', async () => {
await node.close();
});
node.on('abort', async (err) => {
const timeout = setTimeout(() => {
2022-06-29 14:03:44 +10:00
console.error('Shutdown is taking a long time. Exiting.');
process.exit(3);
}, 5000);
timeout.unref();
try {
console.error('Shutting down...');
await node.close();
clearTimeout(timeout);
console.error(err.stack);
process.exit(2);
} catch (e) {
console.error(`Error occurred during shutdown: ${e.message}`);
process.exit(3);
}
});
2017-06-29 20:54:07 -07:00
(async () => {
await node.ensure();
await node.open();
await node.connect();
2016-07-29 15:40:39 -07:00
node.startSync();
2017-06-29 20:54:07 -07:00
})().catch((err) => {
2017-07-17 16:40:16 -07:00
console.error(err.stack);
process.exit(1);
2016-03-22 17:36:58 -07:00
});