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':
|
case 'reload':
|
||||||
meta.reload();
|
meta.reload();
|
||||||
break;
|
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 = [],
|
workers = [],
|
||||||
|
|
||||||
Loader = {
|
Loader = {
|
||||||
timesStarted: 0,
|
timesStarted: 0
|
||||||
js: {
|
|
||||||
target: {}
|
|
||||||
},
|
|
||||||
css: {
|
|
||||||
cache: undefined,
|
|
||||||
acpCache: undefined
|
|
||||||
},
|
|
||||||
templatesCompiled: false
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Loader.init = function (callback) {
|
Loader.init = function (callback) {
|
||||||
@@ -79,37 +71,13 @@ Loader.addWorkerEvents = function (worker) {
|
|||||||
if (!(worker.suicide || code === 0)) {
|
if (!(worker.suicide || code === 0)) {
|
||||||
console.log('[cluster] Spinning up another process...');
|
console.log('[cluster] Spinning up another process...');
|
||||||
|
|
||||||
forkWorker(worker.index, worker.isPrimary, true);
|
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) {
|
||||||
switch (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':
|
case 'restart':
|
||||||
console.log('[cluster] Restarting...');
|
console.log('[cluster] Restarting...');
|
||||||
Loader.restart();
|
Loader.restart();
|
||||||
@@ -118,31 +86,6 @@ Loader.addWorkerEvents = function (worker) {
|
|||||||
console.log('[cluster] Reloading...');
|
console.log('[cluster] Reloading...');
|
||||||
Loader.reload();
|
Loader.reload();
|
||||||
break;
|
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');
|
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, x === 0, false);
|
forkWorker(x, x === 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (callback) {
|
if (callback) {
|
||||||
@@ -161,7 +104,7 @@ Loader.start = function (callback) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
function forkWorker(index, isPrimary, isRestart) {
|
function forkWorker(index, isPrimary) {
|
||||||
var ports = getPorts();
|
var ports = getPorts();
|
||||||
var args = [];
|
var args = [];
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ var postcss = require('postcss');
|
|||||||
var clean = require('postcss-clean');
|
var clean = require('postcss-clean');
|
||||||
|
|
||||||
var plugins = require('../plugins');
|
var plugins = require('../plugins');
|
||||||
var emitter = require('../emitter');
|
|
||||||
var db = require('../database');
|
var db = require('../database');
|
||||||
var file = require('../file');
|
var file = require('../file');
|
||||||
var utils = require('../../public/src/utils');
|
var utils = require('../../public/src/utils');
|
||||||
@@ -24,10 +23,6 @@ module.exports = function (Meta) {
|
|||||||
|
|
||||||
Meta.css.minify = function (callback) {
|
Meta.css.minify = function (callback) {
|
||||||
callback = callback || function () {};
|
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');
|
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) {
|
||||||
@@ -84,23 +79,8 @@ module.exports = function (Meta) {
|
|||||||
async.series([
|
async.series([
|
||||||
async.apply(minify, source, paths, 'cache'),
|
async.apply(minify, source, paths, 'cache'),
|
||||||
async.apply(minify, acpSource, paths, 'acpCache')
|
async.apply(minify, acpSource, paths, 'acpCache')
|
||||||
], function (err, minified) {
|
], function (err) {
|
||||||
if (err) {
|
callback(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();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -110,23 +90,8 @@ module.exports = function (Meta) {
|
|||||||
async.series([
|
async.series([
|
||||||
async.apply(Meta.css.loadFile, path.join(__dirname, '../../public/stylesheet.css'), 'cache'),
|
async.apply(Meta.css.loadFile, path.join(__dirname, '../../public/stylesheet.css'), 'cache'),
|
||||||
async.apply(Meta.css.loadFile, path.join(__dirname, '../../public/admin.css'), 'acpCache')
|
async.apply(Meta.css.loadFile, path.join(__dirname, '../../public/admin.css'), 'acpCache')
|
||||||
], function (err, minified) {
|
], function (err) {
|
||||||
if (err) {
|
callback(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();
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ var nconf = require('nconf');
|
|||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
var file = require('../file');
|
var file = require('../file');
|
||||||
var plugins = require('../plugins');
|
var plugins = require('../plugins');
|
||||||
var emitter = require('../emitter');
|
|
||||||
var utils = require('../../public/src/utils');
|
var utils = require('../../public/src/utils');
|
||||||
|
|
||||||
module.exports = function (Meta) {
|
module.exports = function (Meta) {
|
||||||
@@ -122,14 +121,6 @@ module.exports = function (Meta) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Meta.js.minify = function (target, callback) {
|
Meta.js.minify = function (target, callback) {
|
||||||
if (nconf.get('isPrimary') !== 'true') {
|
|
||||||
if (typeof callback === 'function') {
|
|
||||||
callback();
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
winston.verbose('[meta/js] Minifying ' + target);
|
winston.verbose('[meta/js] Minifying ' + target);
|
||||||
|
|
||||||
var forkProcessParams = setupDebugging();
|
var forkProcessParams = setupDebugging();
|
||||||
@@ -137,7 +128,10 @@ module.exports = function (Meta) {
|
|||||||
|
|
||||||
Meta.js.target[target] = {};
|
Meta.js.target[target] = {};
|
||||||
|
|
||||||
Meta.js.prepare(target, function () {
|
Meta.js.prepare(target, function (err) {
|
||||||
|
if (err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
minifier.send({
|
minifier.send({
|
||||||
action: 'js',
|
action: 'js',
|
||||||
minify: global.env !== 'development',
|
minify: global.env !== 'development',
|
||||||
@@ -153,24 +147,10 @@ module.exports = function (Meta) {
|
|||||||
winston.verbose('[meta/js] ' + target + ' minification complete');
|
winston.verbose('[meta/js] ' + target + ' minification complete');
|
||||||
minifier.kill();
|
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) {
|
if (nconf.get('local-assets') === undefined || nconf.get('local-assets') !== false) {
|
||||||
return Meta.js.commitToFile(target, function () {
|
return Meta.js.commitToFile(target, callback);
|
||||||
if (typeof callback === 'function') {
|
|
||||||
callback();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
emitter.emit('meta:js.compiled');
|
return callback();
|
||||||
if (typeof callback === 'function') {
|
|
||||||
return callback();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@@ -178,11 +158,7 @@ module.exports = function (Meta) {
|
|||||||
winston.error('[meta/js] Could not compile ' + target + ': ' + message.message);
|
winston.error('[meta/js] Could not compile ' + target + ': ' + message.message);
|
||||||
minifier.kill();
|
minifier.kill();
|
||||||
|
|
||||||
if (typeof callback === 'function') {
|
callback(new Error(message.message));
|
||||||
callback(new Error(message.message));
|
|
||||||
} else {
|
|
||||||
process.exit(0);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -236,13 +212,7 @@ module.exports = function (Meta) {
|
|||||||
|
|
||||||
Meta.js.commitToFile = function (target, callback) {
|
Meta.js.commitToFile = function (target, callback) {
|
||||||
fs.writeFile(path.join(__dirname, '../../public/' + target), Meta.js.target[target].cache, function (err) {
|
fs.writeFile(path.join(__dirname, '../../public/' + target), Meta.js.target[target].cache, function (err) {
|
||||||
if (err) {
|
callback(err);
|
||||||
winston.error('[meta/js] ' + err.message);
|
|
||||||
process.exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
emitter.emit('meta:js.compiled');
|
|
||||||
callback();
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -277,7 +247,6 @@ module.exports = function (Meta) {
|
|||||||
map: files[1] || ''
|
map: files[1] || ''
|
||||||
};
|
};
|
||||||
|
|
||||||
emitter.emit('meta:js.compiled');
|
|
||||||
callback();
|
callback();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ var path = require('path');
|
|||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
var nconf = require('nconf');
|
var nconf = require('nconf');
|
||||||
|
|
||||||
var emitter = require('../emitter');
|
|
||||||
var plugins = require('../plugins');
|
var plugins = require('../plugins');
|
||||||
var utils = require('../../public/src/utils');
|
var utils = require('../../public/src/utils');
|
||||||
|
|
||||||
@@ -18,11 +17,6 @@ var searchIndex = {};
|
|||||||
Templates.compile = function (callback) {
|
Templates.compile = function (callback) {
|
||||||
callback = callback || function () {};
|
callback = callback || function () {};
|
||||||
|
|
||||||
if (nconf.get('isPrimary') === 'false') {
|
|
||||||
emitter.emit('templates:compiled');
|
|
||||||
return callback();
|
|
||||||
}
|
|
||||||
|
|
||||||
compile(callback);
|
compile(callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -149,15 +143,12 @@ function compile(callback) {
|
|||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
compileIndex(viewsPath, function () {
|
compileIndex(viewsPath, function (err) {
|
||||||
|
if (err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
winston.verbose('[meta/templates] Successfully compiled templates.');
|
winston.verbose('[meta/templates] Successfully compiled templates.');
|
||||||
|
|
||||||
emitter.emit('templates:compiled');
|
|
||||||
if (process.send) {
|
|
||||||
process.send({
|
|
||||||
action: 'templates:compiled'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
callback();
|
callback();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var meta = require('../meta'),
|
var meta = require('../meta');
|
||||||
user = require('../user'),
|
var user = require('../user');
|
||||||
topics = require('../topics'),
|
var topics = require('../topics');
|
||||||
emitter = require('../emitter'),
|
var emitter = require('../emitter');
|
||||||
|
|
||||||
websockets = require('./'),
|
var websockets = require('./');
|
||||||
|
|
||||||
SocketMeta = {
|
var SocketMeta = {
|
||||||
rooms: {}
|
rooms: {}
|
||||||
};
|
};
|
||||||
|
|
||||||
SocketMeta.reconnected = function (socket, data, callback) {
|
SocketMeta.reconnected = function (socket, data, callback) {
|
||||||
if (socket.uid) {
|
if (socket.uid) {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var async = require('async');
|
var async = require('async');
|
||||||
var winston = require('winston');
|
var winston = require('winston');
|
||||||
|
|
||||||
var user = require('../user');
|
var user = require('../user');
|
||||||
|
|||||||
@@ -62,24 +62,16 @@ module.exports.listen = function (callback) {
|
|||||||
|
|
||||||
logger.init(app);
|
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');
|
winston.info('NodeBB Ready');
|
||||||
emitter.emit('nodebb:ready');
|
emitter.emit('nodebb:ready');
|
||||||
|
|
||||||
listen(callback);
|
listen(callback);
|
||||||
});
|
});
|
||||||
|
|
||||||
initializeNodeBB(function (err) {
|
|
||||||
if (err) {
|
|
||||||
winston.error(err);
|
|
||||||
process.exit();
|
|
||||||
}
|
|
||||||
if (process.send) {
|
|
||||||
process.send({
|
|
||||||
action: 'ready'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function initializeNodeBB(callback) {
|
function initializeNodeBB(callback) {
|
||||||
@@ -108,10 +100,6 @@ function initializeNodeBB(callback) {
|
|||||||
},
|
},
|
||||||
function (next) {
|
function (next) {
|
||||||
async.series([
|
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, 'nodebb.min.js'),
|
||||||
async.apply(meta.js.getFromFile, 'acp.min.js'),
|
async.apply(meta.js.getFromFile, 'acp.min.js'),
|
||||||
async.apply(meta.css.getFromFile),
|
async.apply(meta.css.getFromFile),
|
||||||
|
|||||||
Reference in New Issue
Block a user