v1.18.x
barisusakli 10 years ago
parent d1b457b066
commit 363057cf49

@ -25,6 +25,7 @@ nconf.argv().env();
var fs = require('fs'), var fs = require('fs'),
os = require('os'), os = require('os'),
async = require('async'),
semver = require('semver'), semver = require('semver'),
winston = require('winston'), winston = require('winston'),
path = require('path'), path = require('path'),
@ -141,14 +142,21 @@ function start() {
nconf.set('url', nconf.get('base_url') + (nconf.get('use_port') ? ':' + nconf.get('port') : '') + nconf.get('relative_path')); nconf.set('url', nconf.get('base_url') + (nconf.get('use_port') ? ':' + nconf.get('port') : '') + nconf.get('relative_path'));
plugins.ready(function() { async.waterfall([
webserver.init(function() { async.apply(plugins.ready),
webserver.listen(function() { async.apply(webserver.init),
async.apply(webserver.listen)
], function(err) {
if (err) {
winston.error(err.stack);
process.exit();
}
if (process.send) {
process.send({ process.send({
action: 'ready' action: 'ready'
}); });
}); }
});
}); });
process.on('SIGTERM', shutdown); process.on('SIGTERM', shutdown);

@ -17,12 +17,10 @@ var mkdirp = require('mkdirp'),
Templates.compile = function(callback) { Templates.compile = function(callback) {
if (cluster.isWorker && process.env.cluster_setup !== 'true') { if (cluster.isWorker && process.env.cluster_setup !== 'true') {
return setTimeout(function() {
emitter.emit('templates:compiled'); emitter.emit('templates:compiled');
if (callback) { if (callback) {
callback(); callback();
} }
}, 1000);
} }
var coreTemplatesPath = nconf.get('core_templates_path'), var coreTemplatesPath = nconf.get('core_templates_path'),

@ -108,7 +108,6 @@ module.exports = function(app, data) {
auth.initialize(app, middleware); auth.initialize(app, middleware);
routeCurrentTheme(app, data.currentThemeId, data.themesData); routeCurrentTheme(app, data.currentThemeId, data.themesData);
meta.templates.compile();
return middleware; return middleware;
}; };

@ -100,9 +100,7 @@ if(nconf.get('ssl')) {
winston.info('Using ports 80 and 443 is not recommend; use a proxy instead. See README.md'); winston.info('Using ports 80 and 443 is not recommend; use a proxy instead. See README.md');
} }
module.exports.server = server; server.on('error', function(err) {
module.exports.init = function(callback) {
server.on("error", function(err){
winston.error(err.stack); winston.error(err.stack);
console.log(err.stack); console.log(err.stack);
if (err.code === 'EADDRINUSE') { if (err.code === 'EADDRINUSE') {
@ -117,24 +115,28 @@ if(nconf.get('ssl')) {
} }
}); });
module.exports.server = server;
module.exports.init = function(callback) {
emitter.all(['templates:compiled', 'meta:js.compiled', 'meta:css.compiled'], function() { emitter.all(['templates:compiled', 'meta:js.compiled', 'meta:css.compiled'], function() {
winston.info('NodeBB Ready'); winston.info('NodeBB Ready');
emitter.emit('nodebb:ready'); emitter.emit('nodebb:ready');
emitter.removeAllListeners('templates:compiled').removeAllListeners('meta:js.compiled').removeAllListeners('meta:css.compiled'); emitter.removeAllListeners('templates:compiled').removeAllListeners('meta:js.compiled').removeAllListeners('meta:css.compiled');
}); });
if (process.send) { meta.templates.compile(callback);
callback();
} else {
module.exports.listen();
}
}; };
module.exports.listen = function(callback) { module.exports.listen = function(callback) {
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;
winston.info('NodeBB attempting to listen on: ' + bind_address); winston.info('NodeBB attempting to listen on: ' + bind_address);
server.listen(port, nconf.get('bind_address'), function() { server.listen(port, nconf.get('bind_address'), function(err) {
if (err) {
return callback(err);
}
winston.info('NodeBB is now listening on: ' + bind_address); winston.info('NodeBB is now listening on: ' + bind_address);
if (process.send) { if (process.send) {
process.send({ process.send({
@ -144,9 +146,7 @@ if(nconf.get('ssl')) {
}); });
} }
if (typeof callback === 'function') {
callback(); callback();
}
}); });
}; };

Loading…
Cancel
Save