Cluster + instance improvements
-Moved the database initialize call out of the instance code into the prestart script so that it is now only called once when you start the explorer even if you are running multiple cpus/threads -The database connection function now uses the default connection string in the event a connection string is not supplied -Removed unused reference to lib/explorer.js code from the cluster file
This commit is contained in:
@@ -2,7 +2,6 @@ var cluster = require('cluster');
|
|||||||
|
|
||||||
if (cluster.isMaster) {
|
if (cluster.isMaster) {
|
||||||
const isWinOS = process.platform == 'win32';
|
const isWinOS = process.platform == 'win32';
|
||||||
const lib = require('../lib/explorer');
|
|
||||||
const instances = (process.argv[2] != null && process.argv[2] != '' && !isNaN(process.argv[2]) && Number.isInteger(parseFloat(process.argv[2])) ? parseInt(process.argv[2]) : require('os').cpus().length);
|
const instances = (process.argv[2] != null && process.argv[2] != '' && !isNaN(process.argv[2]) && Number.isInteger(parseFloat(process.argv[2])) ? parseInt(process.argv[2]) : require('os').cpus().length);
|
||||||
|
|
||||||
console.log('Starting cluster with pid: ' + process.pid);
|
console.log('Starting cluster with pid: ' + process.pid);
|
||||||
|
|||||||
+1
-10
@@ -6,15 +6,7 @@ var app = require('../app');
|
|||||||
|
|
||||||
app.set('port', process.env.PORT || settings.webserver.port);
|
app.set('port', process.env.PORT || settings.webserver.port);
|
||||||
|
|
||||||
var dbString = 'mongodb://' + encodeURIComponent(settings.dbsettings.user);
|
db.connect(null, function() {
|
||||||
dbString = dbString + ':' + encodeURIComponent(settings.dbsettings.password);
|
|
||||||
dbString = dbString + '@' + settings.dbsettings.address;
|
|
||||||
dbString = dbString + ':' + settings.dbsettings.port;
|
|
||||||
dbString = dbString + '/' + settings.dbsettings.database;
|
|
||||||
|
|
||||||
db.connect(dbString, function() {
|
|
||||||
// initialize the database
|
|
||||||
db.initialize_data_startup(function() {
|
|
||||||
var server = app.listen(app.get('port'), '::', function() {
|
var server = app.listen(app.get('port'), '::', function() {
|
||||||
debug('Express server listening on port ' + server.address().port);
|
debug('Express server listening on port ' + server.address().port);
|
||||||
});
|
});
|
||||||
@@ -33,4 +25,3 @@ db.connect(dbString, function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
@@ -286,6 +286,13 @@ module.exports = {
|
|||||||
connect: function(database, cb) {
|
connect: function(database, cb) {
|
||||||
mongoose.set('strictQuery', true);
|
mongoose.set('strictQuery', true);
|
||||||
|
|
||||||
|
if (database == null)
|
||||||
|
database = 'mongodb://' + encodeURIComponent(settings.dbsettings.user) +
|
||||||
|
':' + encodeURIComponent(settings.dbsettings.password) +
|
||||||
|
'@' + settings.dbsettings.address +
|
||||||
|
':' + settings.dbsettings.port +
|
||||||
|
'/' + settings.dbsettings.database;
|
||||||
|
|
||||||
mongoose.connect(database).then(() => {
|
mongoose.connect(database).then(() => {
|
||||||
return cb();
|
return cb();
|
||||||
}).catch((err) => {
|
}).catch((err) => {
|
||||||
|
|||||||
+9
-1
@@ -10,7 +10,7 @@ var nodeVersionRevision = '0';
|
|||||||
|
|
||||||
// check if the nodejs version # is blank or a very long string as that would usually indicate a problem
|
// check if the nodejs version # is blank or a very long string as that would usually indicate a problem
|
||||||
if (nodeVersion != null && nodeVersion != '' && nodeVersion.length < 16) {
|
if (nodeVersion != null && nodeVersion != '' && nodeVersion.length < 16) {
|
||||||
// Remove the 'v' from the beginning of the version string
|
// remove the 'v' from the beginning of the version string
|
||||||
if (nodeVersion.indexOf('v') == 0)
|
if (nodeVersion.indexOf('v') == 0)
|
||||||
nodeVersion = nodeVersion.slice(1);
|
nodeVersion = nodeVersion.slice(1);
|
||||||
|
|
||||||
@@ -99,6 +99,12 @@ check_arguments_passed(function(pidName, node_env) {
|
|||||||
// compile scss to css
|
// compile scss to css
|
||||||
execSync('node ./scripts/compile_css.js', {stdio : 'inherit'});
|
execSync('node ./scripts/compile_css.js', {stdio : 'inherit'});
|
||||||
|
|
||||||
|
const db = require('../lib/database');
|
||||||
|
|
||||||
|
// connect to the mongo database
|
||||||
|
db.connect(null, function() {
|
||||||
|
// initialize the database
|
||||||
|
db.initialize_data_startup(function() {
|
||||||
// check if the webserver should be started from here based on the pidName
|
// check if the webserver should be started from here based on the pidName
|
||||||
switch (pidName) {
|
switch (pidName) {
|
||||||
case 'pm2':
|
case 'pm2':
|
||||||
@@ -144,3 +150,5 @@ check_arguments_passed(function(pidName, node_env) {
|
|||||||
// finished pre-loading
|
// finished pre-loading
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user