Ivan Socolsky
10 years ago
2 changed files with 56 additions and 15 deletions
@ -1,18 +1,50 @@ |
|||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||
|
|
||||
|
var fs = require('fs'); |
||||
|
|
||||
var ExpressApp = require('./lib/expressapp'); |
var ExpressApp = require('./lib/expressapp'); |
||||
var WsApp = require('./lib/wsapp'); |
var WsApp = require('./lib/wsapp'); |
||||
var config = require('./config'); |
var config = require('./config'); |
||||
|
|
||||
var port = process.env.BWS_PORT || config.port || 3232; |
var port = process.env.BWS_PORT || config.port || 3232; |
||||
|
|
||||
var app = ExpressApp.start(config); |
var cluster = require('cluster'); |
||||
//app.listen(port);
|
var http = require('http'); |
||||
|
var numCPUs = require('os').cpus().length; |
||||
|
|
||||
var server = require('http').Server(app); |
var serverModule = config.https ? require('https') : require('http'); |
||||
|
var serverOpts = {}; |
||||
|
|
||||
var ws = WsApp.start(server, config); |
if (config.https) { |
||||
|
serverOpts.key = fs.readFileSync(config.privateKeyFile || './ssl/privatekey.pem'); |
||||
|
serverOpts.cert = fs.readFileSync(config.certificateFile || './ssl/certificate.pem'); |
||||
|
} |
||||
|
|
||||
|
var startOne = function() { |
||||
|
var app = ExpressApp.start(config); |
||||
|
var server = config.https ? serverModule.createServer(serverOpts, app) : |
||||
|
serverModule.Server(app); |
||||
|
var ws = WsApp.start(server, config); |
||||
server.listen(port); |
server.listen(port); |
||||
|
|
||||
console.log('Bitcore Wallet Service running on port ' + port); |
console.log('Bitcore Wallet Service running on port ' + port); |
||||
|
}; |
||||
|
|
||||
|
if (!config.cluster) { |
||||
|
startOne(); |
||||
|
} else { |
||||
|
if (!config.storageOpts.multiLevel || !config.lockOpts.lockerServer) |
||||
|
throw 'When running in cluster mode, multilevel and locker server need to be configured'; |
||||
|
|
||||
|
var clusterInstances = config.clusterInstances || numCpus; |
||||
|
|
||||
|
if (cluster.isMaster) { |
||||
|
for (var i = 0; i < clusterInstances; i++) { |
||||
|
cluster.fork(); |
||||
|
} |
||||
|
cluster.on('exit', function(worker, code, signal) { |
||||
|
console.log('worker ' + worker.process.pid + ' died'); |
||||
|
}); |
||||
|
} else { |
||||
|
startOne(); |
||||
|
} |
||||
|
} |
||||
|
Loading…
Reference in new issue