mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-29 10:06:13 +01:00
14
app.js
14
app.js
@@ -164,20 +164,6 @@ function start() {
|
||||
case 'reload':
|
||||
meta.reload();
|
||||
break;
|
||||
case 'js-propagate':
|
||||
meta.js.target = message.data;
|
||||
emitter.emit('meta:js.compiled');
|
||||
winston.verbose('[cluster] Client-side javascript and mapping propagated to worker %s', process.pid);
|
||||
break;
|
||||
case 'css-propagate':
|
||||
meta.css.cache = message.cache;
|
||||
meta.css.acpCache = message.acpCache;
|
||||
emitter.emit('meta:css.compiled');
|
||||
winston.verbose('[cluster] Stylesheets propagated to worker %s', process.pid);
|
||||
break;
|
||||
case 'templates:compiled':
|
||||
emitter.emit('templates:compiled');
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
65
loader.js
65
loader.js
@@ -22,15 +22,7 @@ var pidFilePath = __dirname + '/pidfile',
|
||||
workers = [],
|
||||
|
||||
Loader = {
|
||||
timesStarted: 0,
|
||||
js: {
|
||||
target: {}
|
||||
},
|
||||
css: {
|
||||
cache: undefined,
|
||||
acpCache: undefined
|
||||
},
|
||||
templatesCompiled: false
|
||||
timesStarted: 0
|
||||
};
|
||||
|
||||
Loader.init = function (callback) {
|
||||
@@ -79,37 +71,13 @@ Loader.addWorkerEvents = function (worker) {
|
||||
if (!(worker.suicide || code === 0)) {
|
||||
console.log('[cluster] Spinning up another process...');
|
||||
|
||||
forkWorker(worker.index, worker.isPrimary, true);
|
||||
forkWorker(worker.index, worker.isPrimary);
|
||||
}
|
||||
});
|
||||
|
||||
worker.on('message', function (message) {
|
||||
if (message && typeof message === 'object' && message.action) {
|
||||
switch (message.action) {
|
||||
case 'ready':
|
||||
if (Loader.js.target['nodebb.min.js'] && Loader.js.target['acp.min.js'] && !worker.isPrimary) {
|
||||
worker.send({
|
||||
action: 'js-propagate',
|
||||
data: Loader.js.target
|
||||
});
|
||||
}
|
||||
|
||||
if (Loader.css.cache && !worker.isPrimary) {
|
||||
worker.send({
|
||||
action: 'css-propagate',
|
||||
cache: Loader.css.cache,
|
||||
acpCache: Loader.css.acpCache
|
||||
});
|
||||
}
|
||||
|
||||
if (Loader.templatesCompiled && !worker.isPrimary) {
|
||||
worker.send({
|
||||
action: 'templates:compiled'
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
break;
|
||||
case 'restart':
|
||||
console.log('[cluster] Restarting...');
|
||||
Loader.restart();
|
||||
@@ -118,31 +86,6 @@ Loader.addWorkerEvents = function (worker) {
|
||||
console.log('[cluster] Reloading...');
|
||||
Loader.reload();
|
||||
break;
|
||||
case 'js-propagate':
|
||||
Loader.js.target = message.data;
|
||||
|
||||
Loader.notifyWorkers({
|
||||
action: 'js-propagate',
|
||||
data: message.data
|
||||
}, worker.pid);
|
||||
break;
|
||||
case 'css-propagate':
|
||||
Loader.css.cache = message.cache;
|
||||
Loader.css.acpCache = message.acpCache;
|
||||
|
||||
Loader.notifyWorkers({
|
||||
action: 'css-propagate',
|
||||
cache: message.cache,
|
||||
acpCache: message.acpCache
|
||||
}, worker.pid);
|
||||
break;
|
||||
case 'templates:compiled':
|
||||
Loader.templatesCompiled = true;
|
||||
|
||||
Loader.notifyWorkers({
|
||||
action: 'templates:compiled',
|
||||
}, worker.pid);
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -153,7 +96,7 @@ Loader.start = function (callback) {
|
||||
console.log('Clustering enabled: Spinning up ' + numProcs + ' process(es).\n');
|
||||
|
||||
for (var x = 0; x < numProcs; ++x) {
|
||||
forkWorker(x, x === 0, false);
|
||||
forkWorker(x, x === 0);
|
||||
}
|
||||
|
||||
if (callback) {
|
||||
@@ -161,7 +104,7 @@ Loader.start = function (callback) {
|
||||
}
|
||||
};
|
||||
|
||||
function forkWorker(index, isPrimary, isRestart) {
|
||||
function forkWorker(index, isPrimary) {
|
||||
var ports = getPorts();
|
||||
var args = [];
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@ var postcss = require('postcss');
|
||||
var clean = require('postcss-clean');
|
||||
|
||||
var plugins = require('../plugins');
|
||||
var emitter = require('../emitter');
|
||||
var db = require('../database');
|
||||
var file = require('../file');
|
||||
var utils = require('../../public/src/utils');
|
||||
@@ -24,10 +23,6 @@ module.exports = function (Meta) {
|
||||
|
||||
Meta.css.minify = function (callback) {
|
||||
callback = callback || function () {};
|
||||
if (nconf.get('isPrimary') !== 'true') {
|
||||
winston.verbose('[meta/css] Cluster worker ' + process.pid + ' skipping LESS/CSS compilation');
|
||||
return callback();
|
||||
}
|
||||
|
||||
winston.verbose('[meta/css] Minifying LESS/CSS');
|
||||
db.getObjectFields('config', ['theme:type', 'theme:id'], function (err, themeData) {
|
||||
@@ -84,23 +79,8 @@ module.exports = function (Meta) {
|
||||
async.series([
|
||||
async.apply(minify, source, paths, 'cache'),
|
||||
async.apply(minify, acpSource, paths, 'acpCache')
|
||||
], function (err, minified) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
// Propagate to other workers
|
||||
if (process.send) {
|
||||
process.send({
|
||||
action: 'css-propagate',
|
||||
cache: minified[0],
|
||||
acpCache: minified[1]
|
||||
});
|
||||
}
|
||||
|
||||
emitter.emit('meta:css.compiled');
|
||||
|
||||
callback();
|
||||
], function (err) {
|
||||
callback(err);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -110,23 +90,8 @@ module.exports = function (Meta) {
|
||||
async.series([
|
||||
async.apply(Meta.css.loadFile, path.join(__dirname, '../../public/stylesheet.css'), 'cache'),
|
||||
async.apply(Meta.css.loadFile, path.join(__dirname, '../../public/admin.css'), 'acpCache')
|
||||
], function (err, minified) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
// Propagate to other workers
|
||||
if (process.send) {
|
||||
process.send({
|
||||
action: 'css-propagate',
|
||||
cache: Meta.css.cache,
|
||||
acpCache: Meta.css.acpCache
|
||||
});
|
||||
}
|
||||
|
||||
emitter.emit('meta:css.compiled');
|
||||
|
||||
callback();
|
||||
], function (err) {
|
||||
callback(err);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@ var nconf = require('nconf');
|
||||
var fs = require('fs');
|
||||
var file = require('../file');
|
||||
var plugins = require('../plugins');
|
||||
var emitter = require('../emitter');
|
||||
var utils = require('../../public/src/utils');
|
||||
|
||||
module.exports = function (Meta) {
|
||||
@@ -122,14 +121,6 @@ module.exports = function (Meta) {
|
||||
};
|
||||
|
||||
Meta.js.minify = function (target, callback) {
|
||||
if (nconf.get('isPrimary') !== 'true') {
|
||||
if (typeof callback === 'function') {
|
||||
callback();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
winston.verbose('[meta/js] Minifying ' + target);
|
||||
|
||||
var forkProcessParams = setupDebugging();
|
||||
@@ -137,7 +128,10 @@ module.exports = function (Meta) {
|
||||
|
||||
Meta.js.target[target] = {};
|
||||
|
||||
Meta.js.prepare(target, function () {
|
||||
Meta.js.prepare(target, function (err) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
minifier.send({
|
||||
action: 'js',
|
||||
minify: global.env !== 'development',
|
||||
@@ -153,36 +147,18 @@ module.exports = function (Meta) {
|
||||
winston.verbose('[meta/js] ' + target + ' minification complete');
|
||||
minifier.kill();
|
||||
|
||||
if (process.send && Meta.js.target['nodebb.min.js'] && Meta.js.target['acp.min.js']) {
|
||||
process.send({
|
||||
action: 'js-propagate',
|
||||
data: Meta.js.target
|
||||
});
|
||||
}
|
||||
|
||||
if (nconf.get('local-assets') === undefined || nconf.get('local-assets') !== false) {
|
||||
return Meta.js.commitToFile(target, function () {
|
||||
if (typeof callback === 'function') {
|
||||
callback();
|
||||
}
|
||||
});
|
||||
return Meta.js.commitToFile(target, callback);
|
||||
} else {
|
||||
emitter.emit('meta:js.compiled');
|
||||
if (typeof callback === 'function') {
|
||||
return callback();
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case 'error':
|
||||
winston.error('[meta/js] Could not compile ' + target + ': ' + message.message);
|
||||
minifier.kill();
|
||||
|
||||
if (typeof callback === 'function') {
|
||||
callback(new Error(message.message));
|
||||
} else {
|
||||
process.exit(0);
|
||||
}
|
||||
break;
|
||||
}
|
||||
});
|
||||
@@ -236,13 +212,7 @@ module.exports = function (Meta) {
|
||||
|
||||
Meta.js.commitToFile = function (target, callback) {
|
||||
fs.writeFile(path.join(__dirname, '../../public/' + target), Meta.js.target[target].cache, function (err) {
|
||||
if (err) {
|
||||
winston.error('[meta/js] ' + err.message);
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
emitter.emit('meta:js.compiled');
|
||||
callback();
|
||||
callback(err);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -277,7 +247,6 @@ module.exports = function (Meta) {
|
||||
map: files[1] || ''
|
||||
};
|
||||
|
||||
emitter.emit('meta:js.compiled');
|
||||
callback();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -8,7 +8,6 @@ var path = require('path');
|
||||
var fs = require('fs');
|
||||
var nconf = require('nconf');
|
||||
|
||||
var emitter = require('../emitter');
|
||||
var plugins = require('../plugins');
|
||||
var utils = require('../../public/src/utils');
|
||||
|
||||
@@ -18,11 +17,6 @@ var searchIndex = {};
|
||||
Templates.compile = function (callback) {
|
||||
callback = callback || function () {};
|
||||
|
||||
if (nconf.get('isPrimary') === 'false') {
|
||||
emitter.emit('templates:compiled');
|
||||
return callback();
|
||||
}
|
||||
|
||||
compile(callback);
|
||||
};
|
||||
|
||||
@@ -149,15 +143,12 @@ function compile(callback) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
compileIndex(viewsPath, function () {
|
||||
compileIndex(viewsPath, function (err) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
winston.verbose('[meta/templates] Successfully compiled templates.');
|
||||
|
||||
emitter.emit('templates:compiled');
|
||||
if (process.send) {
|
||||
process.send({
|
||||
action: 'templates:compiled'
|
||||
});
|
||||
}
|
||||
callback();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
'use strict';
|
||||
|
||||
var meta = require('../meta'),
|
||||
user = require('../user'),
|
||||
topics = require('../topics'),
|
||||
emitter = require('../emitter'),
|
||||
var meta = require('../meta');
|
||||
var user = require('../user');
|
||||
var topics = require('../topics');
|
||||
var emitter = require('../emitter');
|
||||
|
||||
websockets = require('./'),
|
||||
var websockets = require('./');
|
||||
|
||||
SocketMeta = {
|
||||
var SocketMeta = {
|
||||
rooms: {}
|
||||
};
|
||||
|
||||
|
||||
@@ -62,24 +62,16 @@ module.exports.listen = function (callback) {
|
||||
|
||||
logger.init(app);
|
||||
|
||||
emitter.all(['templates:compiled', 'meta:js.compiled', 'meta:css.compiled'], function () {
|
||||
initializeNodeBB(function (err) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
winston.info('NodeBB Ready');
|
||||
emitter.emit('nodebb:ready');
|
||||
|
||||
listen(callback);
|
||||
});
|
||||
|
||||
initializeNodeBB(function (err) {
|
||||
if (err) {
|
||||
winston.error(err);
|
||||
process.exit();
|
||||
}
|
||||
if (process.send) {
|
||||
process.send({
|
||||
action: 'ready'
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
function initializeNodeBB(callback) {
|
||||
@@ -108,10 +100,6 @@ function initializeNodeBB(callback) {
|
||||
},
|
||||
function (next) {
|
||||
async.series([
|
||||
async.apply(function(next) {
|
||||
emitter.emit('templates:compiled');
|
||||
setImmediate(next);
|
||||
}),
|
||||
async.apply(meta.js.getFromFile, 'nodebb.min.js'),
|
||||
async.apply(meta.js.getFromFile, 'acp.min.js'),
|
||||
async.apply(meta.css.getFromFile),
|
||||
|
||||
Reference in New Issue
Block a user