mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 19:46:01 +01:00
removed node cluster spawn procs on ports
This commit is contained in:
22
app.js
22
app.js
@@ -30,7 +30,6 @@ var fs = require('fs'),
|
|||||||
semver = require('semver'),
|
semver = require('semver'),
|
||||||
winston = require('winston'),
|
winston = require('winston'),
|
||||||
path = require('path'),
|
path = require('path'),
|
||||||
cluster = require('cluster'),
|
|
||||||
pkg = require('./package.json'),
|
pkg = require('./package.json'),
|
||||||
utils = require('./public/src/utils.js');
|
utils = require('./public/src/utils.js');
|
||||||
|
|
||||||
@@ -60,7 +59,7 @@ if(os.platform() === 'linux') {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!cluster.isWorker) {
|
if (!process.send) {
|
||||||
// If run using `node app`, log GNU copyright info along with server info
|
// If run using `node app`, log GNU copyright info along with server info
|
||||||
winston.info('NodeBB v' + pkg.version + ' Copyright (C) 2013-2014 NodeBB Inc.');
|
winston.info('NodeBB v' + pkg.version + ' Copyright (C) 2013-2014 NodeBB Inc.');
|
||||||
winston.info('This program comes with ABSOLUTELY NO WARRANTY.');
|
winston.info('This program comes with ABSOLUTELY NO WARRANTY.');
|
||||||
@@ -98,6 +97,11 @@ function loadConfig() {
|
|||||||
views_dir: path.join(__dirname, 'public/templates')
|
views_dir: path.join(__dirname, 'public/templates')
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (!nconf.get('isCluster')) {
|
||||||
|
nconf.set('isPrimary', 'true');
|
||||||
|
nconf.set('isCluster', 'false');
|
||||||
|
}
|
||||||
|
|
||||||
// Ensure themes_path is a full filepath
|
// Ensure themes_path is a full filepath
|
||||||
nconf.set('themes_path', path.resolve(__dirname, nconf.get('themes_path')));
|
nconf.set('themes_path', path.resolve(__dirname, nconf.get('themes_path')));
|
||||||
nconf.set('core_templates_path', path.join(__dirname, 'src/views'));
|
nconf.set('core_templates_path', path.join(__dirname, 'src/views'));
|
||||||
@@ -119,13 +123,11 @@ function start() {
|
|||||||
nconf.set('port', urlObject.port || nconf.get('port') || nconf.get('PORT') || 4567);
|
nconf.set('port', urlObject.port || nconf.get('port') || nconf.get('PORT') || 4567);
|
||||||
nconf.set('upload_url', relativePath + '/uploads/');
|
nconf.set('upload_url', relativePath + '/uploads/');
|
||||||
|
|
||||||
if (!cluster.isWorker || process.env.cluster_setup === 'true') {
|
if (nconf.get('isPrimary') === 'true') {
|
||||||
winston.info('Time: %s', (new Date()).toString());
|
winston.info('Time: %s', (new Date()).toString());
|
||||||
winston.info('Initializing NodeBB v%s', pkg.version);
|
winston.info('Initializing NodeBB v%s', pkg.version);
|
||||||
winston.verbose('* using configuration stored in: %s', configFile);
|
winston.verbose('* using configuration stored in: %s', configFile);
|
||||||
}
|
|
||||||
|
|
||||||
if (cluster.isWorker && process.env.cluster_setup === 'true') {
|
|
||||||
var host = nconf.get(nconf.get('database') + ':host'),
|
var host = nconf.get(nconf.get('database') + ':host'),
|
||||||
storeLocation = host ? 'at ' + host + (host.indexOf('/') === -1 ? ':' + nconf.get(nconf.get('database') + ':port') : '') : '';
|
storeLocation = host ? 'at ' + host + (host.indexOf('/') === -1 ? ':' + nconf.get(nconf.get('database') + ':port') : '') : '';
|
||||||
|
|
||||||
@@ -157,7 +159,7 @@ function start() {
|
|||||||
webserver.init();
|
webserver.init();
|
||||||
sockets.init(webserver.server);
|
sockets.init(webserver.server);
|
||||||
|
|
||||||
if (cluster.isWorker && process.env.handle_jobs === 'true') {
|
if (nconf.get('isPrimary')) {
|
||||||
require('./src/notifications').init();
|
require('./src/notifications').init();
|
||||||
require('./src/user').startJobs();
|
require('./src/user').startJobs();
|
||||||
}
|
}
|
||||||
@@ -191,13 +193,13 @@ function start() {
|
|||||||
meta.js.cache = message.cache;
|
meta.js.cache = message.cache;
|
||||||
meta.js.map = message.map;
|
meta.js.map = message.map;
|
||||||
meta.js.hash = message.hash;
|
meta.js.hash = message.hash;
|
||||||
winston.verbose('[cluster] Client-side javascript and mapping propagated to worker %s', cluster.worker.id);
|
winston.verbose('[cluster] Client-side javascript and mapping propagated to worker %s', process.pid);
|
||||||
break;
|
break;
|
||||||
case 'css-propagate':
|
case 'css-propagate':
|
||||||
meta.css.cache = message.cache;
|
meta.css.cache = message.cache;
|
||||||
meta.css.acpCache = message.acpCache;
|
meta.css.acpCache = message.acpCache;
|
||||||
meta.css.hash = message.hash;
|
meta.css.hash = message.hash;
|
||||||
winston.verbose('[cluster] Stylesheets propagated to worker %s', cluster.worker.id);
|
winston.verbose('[cluster] Stylesheets propagated to worker %s', process.pid);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -212,12 +214,8 @@ function start() {
|
|||||||
} else {
|
} else {
|
||||||
winston.warn('Your NodeBB schema is out-of-date. Please run the following command to bring your dataset up to spec:');
|
winston.warn('Your NodeBB schema is out-of-date. Please run the following command to bring your dataset up to spec:');
|
||||||
winston.warn(' ./nodebb upgrade');
|
winston.warn(' ./nodebb upgrade');
|
||||||
if (cluster.isWorker) {
|
|
||||||
cluster.worker.kill();
|
|
||||||
} else {
|
|
||||||
process.exit();
|
process.exit();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
202
loader.js
202
loader.js
@@ -5,7 +5,8 @@ var nconf = require('nconf'),
|
|||||||
fs = require('fs'),
|
fs = require('fs'),
|
||||||
url = require('url'),
|
url = require('url'),
|
||||||
path = require('path'),
|
path = require('path'),
|
||||||
cluster = require('cluster'),
|
fork = require('child_process').fork,
|
||||||
|
|
||||||
async = require('async'),
|
async = require('async'),
|
||||||
logrotate = require('logrotate-stream'),
|
logrotate = require('logrotate-stream'),
|
||||||
|
|
||||||
@@ -15,9 +16,8 @@ var nconf = require('nconf'),
|
|||||||
output = logrotate({ file: __dirname + '/logs/output.log', size: '1m', keep: 3, compress: true }),
|
output = logrotate({ file: __dirname + '/logs/output.log', size: '1m', keep: 3, compress: true }),
|
||||||
silent = process.env.NODE_ENV !== 'development',
|
silent = process.env.NODE_ENV !== 'development',
|
||||||
numProcs,
|
numProcs,
|
||||||
handles = {},
|
|
||||||
handleIndex = 0,
|
workers = [],
|
||||||
server,
|
|
||||||
|
|
||||||
Loader = {
|
Loader = {
|
||||||
timesStarted: 0,
|
timesStarted: 0,
|
||||||
@@ -32,11 +32,6 @@ var nconf = require('nconf'),
|
|||||||
};
|
};
|
||||||
|
|
||||||
Loader.init = function(callback) {
|
Loader.init = function(callback) {
|
||||||
cluster.setupMaster({
|
|
||||||
exec: "app.js",
|
|
||||||
silent: silent
|
|
||||||
});
|
|
||||||
Loader.primaryWorker = 1;
|
|
||||||
|
|
||||||
if (silent) {
|
if (silent) {
|
||||||
console.log = function(value) {
|
console.log = function(value) {
|
||||||
@@ -60,8 +55,32 @@ Loader.displayStartupMessages = function(callback) {
|
|||||||
callback();
|
callback();
|
||||||
};
|
};
|
||||||
|
|
||||||
Loader.addClusterEvents = function(callback) {
|
Loader.addWorkerEvents = function(worker) {
|
||||||
cluster.on('fork', function(worker) {
|
|
||||||
|
worker.on('exit', function(code, signal) {
|
||||||
|
if (code !== 0) {
|
||||||
|
if (Loader.timesStarted < numProcs*3) {
|
||||||
|
Loader.timesStarted++;
|
||||||
|
if (Loader.crashTimer) {
|
||||||
|
clearTimeout(Loader.crashTimer);
|
||||||
|
}
|
||||||
|
Loader.crashTimer = setTimeout(function() {
|
||||||
|
Loader.timesStarted = 0;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
console.log(numProcs*3 + ' restarts in 10 seconds, most likely an error on startup. Halting.');
|
||||||
|
process.exit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('[cluster] Child Process (' + worker.pid + ') has exited (code: ' + code + ', signal: ' + signal +')');
|
||||||
|
if (!worker.suicide) {
|
||||||
|
console.log('[cluster] Spinning up another process...');
|
||||||
|
|
||||||
|
forkWorker(worker.index, worker.isPrimary);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
worker.on('message', function(message) {
|
worker.on('message', function(message) {
|
||||||
if (message && typeof message === 'object' && message.action) {
|
if (message && typeof message === 'object' && message.action) {
|
||||||
var otherWorkers;
|
var otherWorkers;
|
||||||
@@ -106,7 +125,7 @@ Loader.addClusterEvents = function(callback) {
|
|||||||
cache: message.cache,
|
cache: message.cache,
|
||||||
map: message.map,
|
map: message.map,
|
||||||
hash: message.hash
|
hash: message.hash
|
||||||
}, worker.id);
|
}, worker.pid);
|
||||||
break;
|
break;
|
||||||
case 'css-propagate':
|
case 'css-propagate':
|
||||||
Loader.css.cache = message.cache;
|
Loader.css.cache = message.cache;
|
||||||
@@ -118,11 +137,11 @@ Loader.addClusterEvents = function(callback) {
|
|||||||
cache: message.cache,
|
cache: message.cache,
|
||||||
acpCache: message.acpCache,
|
acpCache: message.acpCache,
|
||||||
hash: message.hash
|
hash: message.hash
|
||||||
}, worker.id);
|
}, worker.pid);
|
||||||
break;
|
break;
|
||||||
case 'listening':
|
case 'listening':
|
||||||
if (message.primary) {
|
if (message.primary) {
|
||||||
Loader.primaryWorker = parseInt(worker.id, 10);
|
Loader.primaryWorker = parseInt(worker.pid, 10);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'config:update':
|
case 'config:update':
|
||||||
@@ -131,140 +150,57 @@ Loader.addClusterEvents = function(callback) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
cluster.on('listening', function(worker) {
|
|
||||||
console.log('[cluster] Child Process (' + worker.process.pid + ') listening for connections.');
|
|
||||||
});
|
|
||||||
|
|
||||||
cluster.on('exit', function(worker, code, signal) {
|
|
||||||
if (code !== 0) {
|
|
||||||
if (Loader.timesStarted < numProcs*3) {
|
|
||||||
Loader.timesStarted++;
|
|
||||||
if (Loader.crashTimer) {
|
|
||||||
clearTimeout(Loader.crashTimer);
|
|
||||||
}
|
|
||||||
Loader.crashTimer = setTimeout(function() {
|
|
||||||
Loader.timesStarted = 0;
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
console.log(numProcs*3 + ' restarts in 10 seconds, most likely an error on startup. Halting.');
|
|
||||||
process.exit();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('[cluster] Child Process (' + worker.process.pid + ') has exited (code: ' + code + ', signal: ' + signal +')');
|
|
||||||
if (!worker.suicide) {
|
|
||||||
console.log('[cluster] Spinning up another process...');
|
|
||||||
|
|
||||||
var wasPrimary = parseInt(worker.id, 10) === Loader.primaryWorker;
|
|
||||||
forkWorker(wasPrimary);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
cluster.on('disconnect', function(worker) {
|
|
||||||
console.log('[cluster] Child Process (' + worker.process.pid + ') has disconnected');
|
|
||||||
});
|
|
||||||
|
|
||||||
callback();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Loader.start = function(callback) {
|
Loader.start = function(callback) {
|
||||||
console.log('Clustering enabled: Spinning up ' + numProcs + ' process(es).\n');
|
console.log('Clustering enabled: Spinning up ' + numProcs + ' process(es).\n');
|
||||||
|
|
||||||
for (var x=0; x<numProcs; ++x) {
|
for (var x=0; x<numProcs; ++x) {
|
||||||
forkWorker(x === 0);
|
forkWorker(x, x === 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
var urlObject = url.parse(nconf.get('url'));
|
|
||||||
var port = urlObject.port || nconf.get('port') || nconf.get('PORT') || 4567;
|
|
||||||
nconf.set('port', port);
|
|
||||||
|
|
||||||
server = net.createServer(function(connection) {
|
|
||||||
// remove this once node 0.12.x ships, see https://github.com/elad/node-cluster-socket.io/issues/4
|
|
||||||
connection._handle.readStop();
|
|
||||||
|
|
||||||
var workers = clusterWorkers();
|
|
||||||
var worker = workers[workerIndex(connection.remoteAddress, numProcs)];
|
|
||||||
|
|
||||||
if (worker) {
|
|
||||||
handles[handleIndex] = connection._handle;
|
|
||||||
|
|
||||||
worker.send({action: 'sticky-session:connection', handleIndex: handleIndex}, connection);
|
|
||||||
handleIndex ++;
|
|
||||||
} else {
|
|
||||||
console.log('Cant find worker! Worker count : ' + workers.length);
|
|
||||||
}
|
|
||||||
|
|
||||||
}).listen(port);
|
|
||||||
|
|
||||||
if (callback) {
|
if (callback) {
|
||||||
callback();
|
callback();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
function forkWorker(isPrimary) {
|
function forkWorker(index, isPrimary) {
|
||||||
var worker = cluster.fork({
|
var urlObject = url.parse(nconf.get('url'));
|
||||||
cluster_setup: isPrimary,
|
var port = urlObject.port || nconf.get('port') || nconf.get('PORT') || 4567;
|
||||||
handle_jobs: isPrimary
|
|
||||||
}),
|
|
||||||
output = logrotate({ file: __dirname + '/logs/output.log', size: '1m', keep: 3, compress: true });
|
|
||||||
|
|
||||||
if (silent) {
|
var worker = fork('app.js', [], {
|
||||||
worker.process.stdout.pipe(output);
|
silent: silent,
|
||||||
worker.process.stderr.pipe(output);
|
env: {
|
||||||
}
|
isPrimary: isPrimary,
|
||||||
|
isCluster: true,
|
||||||
worker.on('message', function(message) {
|
port: parseInt(port, 10) + index
|
||||||
if (!message || message.action !== 'sticky-session:accept') {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var _handle = handles[message.handleIndex];
|
|
||||||
|
|
||||||
if (_handle) {
|
|
||||||
_handle.close();
|
|
||||||
|
|
||||||
delete handles[message.handleIndex];
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
function workerIndex(ip, numProcs) {
|
worker.index = index;
|
||||||
var s = '';
|
worker.isPrimary = isPrimary;
|
||||||
for (var i = 0, _len = ip.length; i < _len; i++) {
|
|
||||||
if (parseInt(ip[i], 10)) {
|
|
||||||
s += ip[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Number(s) % numProcs || 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
function clusterWorkers() {
|
workers[index] = worker;
|
||||||
var workers = [];
|
|
||||||
|
|
||||||
for(var i in cluster.workers) {
|
Loader.addWorkerEvents(worker);
|
||||||
workers.push(cluster.workers[i]);
|
|
||||||
|
var output = logrotate({ file: __dirname + '/logs/output.log', size: '1m', keep: 3, compress: true });
|
||||||
|
|
||||||
|
if (silent) {
|
||||||
|
worker.stdout.pipe(output);
|
||||||
|
worker.stderr.pipe(output);
|
||||||
}
|
}
|
||||||
|
|
||||||
return workers;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Loader.restart = function(callback) {
|
Loader.restart = function(callback) {
|
||||||
console.log('[cluster] closing server');
|
|
||||||
|
|
||||||
killWorkers();
|
killWorkers();
|
||||||
|
|
||||||
closeHandles();
|
|
||||||
|
|
||||||
server.close(function() {
|
|
||||||
console.log('[cluster] server closed');
|
|
||||||
Loader.start();
|
Loader.start();
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Loader.reload = function() {
|
Loader.reload = function() {
|
||||||
Object.keys(cluster.workers).forEach(function(worker_id) {
|
workers.forEach(function(worker) {
|
||||||
cluster.workers[worker_id].send({
|
worker.send({
|
||||||
action: 'reload'
|
action: 'reload'
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -275,31 +211,20 @@ Loader.stop = function() {
|
|||||||
|
|
||||||
// Clean up the pidfile
|
// Clean up the pidfile
|
||||||
fs.unlinkSync(__dirname + '/pidfile');
|
fs.unlinkSync(__dirname + '/pidfile');
|
||||||
|
|
||||||
server.close();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function killWorkers() {
|
function killWorkers() {
|
||||||
Object.keys(cluster.workers).forEach(function(id) {
|
workers.forEach(function(worker) {
|
||||||
cluster.workers[id].kill();
|
worker.suicide = true;
|
||||||
|
worker.kill();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function closeHandles() {
|
Loader.notifyWorkers = function (msg, worker_pid) {
|
||||||
for(var h in handles) {
|
worker_pid = parseInt(worker_pid, 10);
|
||||||
var handle = handles[h];
|
workers.forEach(function(worker) {
|
||||||
if (handle) {
|
if (parseInt(worker.pid, 10) !== worker_pid) {
|
||||||
handle.close();
|
worker.send(msg);
|
||||||
delete handles[h];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Loader.notifyWorkers = function (msg, worker_id) {
|
|
||||||
worker_id = parseInt(worker_id, 10);
|
|
||||||
Object.keys(cluster.workers).forEach(function(id) {
|
|
||||||
if (parseInt(id, 10) !== worker_id) {
|
|
||||||
cluster.workers[id].send(msg);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -330,7 +255,6 @@ if (nconf.get('daemon') !== false) {
|
|||||||
async.series([
|
async.series([
|
||||||
Loader.init,
|
Loader.init,
|
||||||
Loader.displayStartupMessages,
|
Loader.displayStartupMessages,
|
||||||
Loader.addClusterEvents,
|
|
||||||
Loader.start
|
Loader.start
|
||||||
], function(err) {
|
], function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ var winston = require('winston'),
|
|||||||
less = require('less'),
|
less = require('less'),
|
||||||
crypto = require('crypto'),
|
crypto = require('crypto'),
|
||||||
async = require('async'),
|
async = require('async'),
|
||||||
cluster = require('cluster'),
|
|
||||||
|
|
||||||
plugins = require('../plugins'),
|
plugins = require('../plugins'),
|
||||||
emitter = require('../emitter'),
|
emitter = require('../emitter'),
|
||||||
@@ -22,7 +21,7 @@ module.exports = function(Meta) {
|
|||||||
Meta.css.defaultBranding = {};
|
Meta.css.defaultBranding = {};
|
||||||
|
|
||||||
Meta.css.minify = function(callback) {
|
Meta.css.minify = function(callback) {
|
||||||
if (!cluster.isWorker || process.env.cluster_setup === 'true') {
|
if (nconf.get('isPrimary') === 'true') {
|
||||||
winston.verbose('[meta/css] Minifying LESS/CSS');
|
winston.verbose('[meta/css] Minifying LESS/CSS');
|
||||||
db.getObjectFields('config', ['theme:type', 'theme:id'], function(err, themeData) {
|
db.getObjectFields('config', ['theme:type', 'theme:id'], function(err, themeData) {
|
||||||
var themeId = (themeData['theme:id'] || 'nodebb-theme-vanilla'),
|
var themeId = (themeData['theme:id'] || 'nodebb-theme-vanilla'),
|
||||||
@@ -64,7 +63,7 @@ module.exports = function(Meta) {
|
|||||||
}
|
}
|
||||||
], function(err, minified) {
|
], function(err, minified) {
|
||||||
// Propagate to other workers
|
// Propagate to other workers
|
||||||
if (cluster.isWorker) {
|
if (process.send) {
|
||||||
process.send({
|
process.send({
|
||||||
action: 'css-propagate',
|
action: 'css-propagate',
|
||||||
cache: minified[0],
|
cache: minified[0],
|
||||||
@@ -81,7 +80,7 @@ module.exports = function(Meta) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
winston.verbose('[meta/css] Cluster worker ' + cluster.worker.id + ' skipping LESS/CSS compilation');
|
winston.verbose('[meta/css] Cluster worker ' + process.pid + ' skipping LESS/CSS compilation');
|
||||||
if (typeof callback === 'function') {
|
if (typeof callback === 'function') {
|
||||||
callback();
|
callback();
|
||||||
}
|
}
|
||||||
@@ -106,7 +105,7 @@ module.exports = function(Meta) {
|
|||||||
acpCachePath = path.join(__dirname, '../../public/admin.css');
|
acpCachePath = path.join(__dirname, '../../public/admin.css');
|
||||||
fs.exists(cachePath, function(exists) {
|
fs.exists(cachePath, function(exists) {
|
||||||
if (exists) {
|
if (exists) {
|
||||||
if (!cluster.isWorker || process.env.cluster_setup === 'true') {
|
if (nconf.get('isPrimary') === 'true') {
|
||||||
winston.verbose('[meta/css] (Experimental) Reading stylesheets from file');
|
winston.verbose('[meta/css] (Experimental) Reading stylesheets from file');
|
||||||
async.map([cachePath, acpCachePath], fs.readFile, function(err, files) {
|
async.map([cachePath, acpCachePath], fs.readFile, function(err, files) {
|
||||||
Meta.css.cache = files[0];
|
Meta.css.cache = files[0];
|
||||||
@@ -149,7 +148,7 @@ module.exports = function(Meta) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Save the compiled CSS in public/ so things like nginx can serve it
|
// Save the compiled CSS in public/ so things like nginx can serve it
|
||||||
if (!cluster.isWorker || process.env.cluster_setup === 'true') {
|
if (nconf.get('isPrimary') === 'true') {
|
||||||
Meta.css.commitToFile(destination);
|
Meta.css.commitToFile(destination);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ var winston = require('winston'),
|
|||||||
_ = require('underscore'),
|
_ = require('underscore'),
|
||||||
os = require('os'),
|
os = require('os'),
|
||||||
nconf = require('nconf'),
|
nconf = require('nconf'),
|
||||||
cluster = require('cluster'),
|
|
||||||
fs = require('fs'),
|
fs = require('fs'),
|
||||||
|
|
||||||
plugins = require('../plugins'),
|
plugins = require('../plugins'),
|
||||||
@@ -127,7 +126,7 @@ module.exports = function(Meta) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Meta.js.minify = function(minify, callback) {
|
Meta.js.minify = function(minify, callback) {
|
||||||
if (!cluster.isWorker || process.env.cluster_setup === 'true') {
|
if (nconf.get('isPrimary') === 'true') {
|
||||||
var minifier = Meta.js.minifierProc = fork('minifier.js'),
|
var minifier = Meta.js.minifierProc = fork('minifier.js'),
|
||||||
onComplete = function(err) {
|
onComplete = function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
@@ -138,7 +137,7 @@ module.exports = function(Meta) {
|
|||||||
winston.verbose('[meta/js] Minification complete');
|
winston.verbose('[meta/js] Minification complete');
|
||||||
minifier.kill();
|
minifier.kill();
|
||||||
|
|
||||||
if (cluster.isWorker) {
|
if (process.send) {
|
||||||
process.send({
|
process.send({
|
||||||
action: 'js-propagate',
|
action: 'js-propagate',
|
||||||
cache: Meta.js.cache,
|
cache: Meta.js.cache,
|
||||||
@@ -214,7 +213,7 @@ module.exports = function(Meta) {
|
|||||||
mapPath = path.join(__dirname, '../../public/nodebb.min.js.map');
|
mapPath = path.join(__dirname, '../../public/nodebb.min.js.map');
|
||||||
fs.exists(scriptPath, function(exists) {
|
fs.exists(scriptPath, function(exists) {
|
||||||
if (exists) {
|
if (exists) {
|
||||||
if (!cluster.isWorker || process.env.cluster_setup === 'true') {
|
if (nconf.get('isPrimary') === 'true') {
|
||||||
winston.verbose('[meta/js] (Experimental) Reading client-side scripts from file');
|
winston.verbose('[meta/js] (Experimental) Reading client-side scripts from file');
|
||||||
async.map([scriptPath, mapPath], fs.readFile, function(err, files) {
|
async.map([scriptPath, mapPath], fs.readFile, function(err, files) {
|
||||||
Meta.js.cache = files[0];
|
Meta.js.cache = files[0];
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ var path = require('path'),
|
|||||||
rimraf = require('rimraf'),
|
rimraf = require('rimraf'),
|
||||||
mkdirp = require('mkdirp'),
|
mkdirp = require('mkdirp'),
|
||||||
async = require('async'),
|
async = require('async'),
|
||||||
cluster = require('cluster'),
|
|
||||||
|
|
||||||
plugins = require('../plugins'),
|
plugins = require('../plugins'),
|
||||||
db = require('../database');
|
db = require('../database');
|
||||||
@@ -17,7 +16,7 @@ module.exports = function(Meta) {
|
|||||||
Meta.sounds = {};
|
Meta.sounds = {};
|
||||||
|
|
||||||
Meta.sounds.init = function(callback) {
|
Meta.sounds.init = function(callback) {
|
||||||
if (cluster.isWorker && process.env.cluster_setup === 'true') {
|
if (nconf.get('isPrimary') === 'true') {
|
||||||
var soundsPath = path.join(__dirname, '../../public/sounds');
|
var soundsPath = path.join(__dirname, '../../public/sounds');
|
||||||
|
|
||||||
plugins.fireHook('filter:sounds.get', [], function(err, filePaths) {
|
plugins.fireHook('filter:sounds.get', [], function(err, filePaths) {
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ var mkdirp = require('mkdirp'),
|
|||||||
path = require('path'),
|
path = require('path'),
|
||||||
fs = require('fs'),
|
fs = require('fs'),
|
||||||
nconf = require('nconf'),
|
nconf = require('nconf'),
|
||||||
cluster = require('cluster'),
|
|
||||||
|
|
||||||
emitter = require('../emitter'),
|
emitter = require('../emitter'),
|
||||||
plugins = require('../plugins'),
|
plugins = require('../plugins'),
|
||||||
@@ -16,7 +15,7 @@ var mkdirp = require('mkdirp'),
|
|||||||
Templates = {};
|
Templates = {};
|
||||||
|
|
||||||
Templates.compile = function(callback) {
|
Templates.compile = function(callback) {
|
||||||
if (cluster.isWorker && process.env.cluster_setup !== 'true') {
|
if (nconf.get('isPrimary') === 'false') {
|
||||||
emitter.emit('templates:compiled');
|
emitter.emit('templates:compiled');
|
||||||
if (callback) {
|
if (callback) {
|
||||||
callback();
|
callback();
|
||||||
@@ -31,7 +30,7 @@ Templates.compile = function(callback) {
|
|||||||
themeConfig = require(nconf.get('theme_config'));
|
themeConfig = require(nconf.get('theme_config'));
|
||||||
|
|
||||||
if (themeConfig.baseTheme) {
|
if (themeConfig.baseTheme) {
|
||||||
var pathToBaseTheme = path.join(nconf.get('themes_path'), themeConfig.baseTheme),
|
var pathToBaseTheme = path.join(nconf.get('themes_path'), themeConfig.baseTheme);
|
||||||
baseTemplatesPath = require(path.join(pathToBaseTheme, 'theme.json')).templates;
|
baseTemplatesPath = require(path.join(pathToBaseTheme, 'theme.json')).templates;
|
||||||
|
|
||||||
if (!baseTemplatesPath){
|
if (!baseTemplatesPath){
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
var async = require('async'),
|
var async = require('async'),
|
||||||
winston = require('winston'),
|
winston = require('winston'),
|
||||||
cluster = require('cluster'),
|
|
||||||
fs = require('fs'),
|
fs = require('fs'),
|
||||||
path = require('path'),
|
path = require('path'),
|
||||||
|
|
||||||
@@ -51,7 +50,7 @@ SocketAdmin.before = function(socket, method, next) {
|
|||||||
|
|
||||||
SocketAdmin.reload = function(socket, data, callback) {
|
SocketAdmin.reload = function(socket, data, callback) {
|
||||||
events.logWithUser(socket.uid, ' is reloading NodeBB');
|
events.logWithUser(socket.uid, ' is reloading NodeBB');
|
||||||
if (cluster.isWorker) {
|
if (process.send) {
|
||||||
process.send({
|
process.send({
|
||||||
action: 'reload'
|
action: 'reload'
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ var path = require('path'),
|
|||||||
server,
|
server,
|
||||||
winston = require('winston'),
|
winston = require('winston'),
|
||||||
async = require('async'),
|
async = require('async'),
|
||||||
cluster = require('cluster'),
|
|
||||||
|
|
||||||
emailer = require('./emailer'),
|
emailer = require('./emailer'),
|
||||||
meta = require('./meta'),
|
meta = require('./meta'),
|
||||||
@@ -82,11 +81,7 @@ if(nconf.get('ssl')) {
|
|||||||
console.log(err.stack);
|
console.log(err.stack);
|
||||||
if (err.code === 'EADDRINUSE') {
|
if (err.code === 'EADDRINUSE') {
|
||||||
winston.error('NodeBB address in use, exiting...');
|
winston.error('NodeBB address in use, exiting...');
|
||||||
if (cluster.isWorker) {
|
|
||||||
cluster.worker.kill();
|
|
||||||
} else {
|
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
@@ -103,9 +98,7 @@ if(nconf.get('ssl')) {
|
|||||||
logger.init(app);
|
logger.init(app);
|
||||||
|
|
||||||
var bind_address = ((nconf.get('bind_address') === "0.0.0.0" || !nconf.get('bind_address')) ? '0.0.0.0' : nconf.get('bind_address')) + ':' + port;
|
var bind_address = ((nconf.get('bind_address') === "0.0.0.0" || !nconf.get('bind_address')) ? '0.0.0.0' : nconf.get('bind_address')) + ':' + port;
|
||||||
if (cluster.isWorker) {
|
|
||||||
port = 0;
|
|
||||||
}
|
|
||||||
server.listen(port, nconf.get('bind_address'), function(err) {
|
server.listen(port, nconf.get('bind_address'), function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
winston.info('NodeBB was unable to listen on: ' + bind_address);
|
winston.info('NodeBB was unable to listen on: ' + bind_address);
|
||||||
@@ -117,7 +110,7 @@ if(nconf.get('ssl')) {
|
|||||||
process.send({
|
process.send({
|
||||||
action: 'listening',
|
action: 'listening',
|
||||||
bind_address: bind_address,
|
bind_address: bind_address,
|
||||||
primary: process.env.handle_jobs === 'true'
|
primary: nconf.get('isPrimary') === 'true'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,13 +118,4 @@ if(nconf.get('ssl')) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
process.on('message', function(message, connection) {
|
|
||||||
if (!message || message.action !== 'sticky-session:connection') {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
process.send({action: 'sticky-session:accept', handleIndex: message.handleIndex});
|
|
||||||
server.emit('connection', connection);
|
|
||||||
});
|
|
||||||
|
|
||||||
}(WebServer));
|
}(WebServer));
|
||||||
|
|||||||
Reference in New Issue
Block a user