mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-12-22 00:10:25 +01:00
closes #2390
This commit is contained in:
22
app.js
22
app.js
@@ -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),
|
||||||
process.send({
|
async.apply(webserver.listen)
|
||||||
action: 'ready'
|
], function(err) {
|
||||||
});
|
if (err) {
|
||||||
|
winston.error(err.stack);
|
||||||
|
process.exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (process.send) {
|
||||||
|
process.send({
|
||||||
|
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,22 +100,24 @@ 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) {
|
winston.error(err.stack);
|
||||||
server.on("error", function(err){
|
console.log(err.stack);
|
||||||
winston.error(err.stack);
|
if (err.code === 'EADDRINUSE') {
|
||||||
console.log(err.stack);
|
winston.error('NodeBB address in use, exiting...');
|
||||||
if (err.code === 'EADDRINUSE') {
|
if (cluster.isWorker) {
|
||||||
winston.error('NodeBB address in use, exiting...');
|
cluster.worker.kill();
|
||||||
if (cluster.isWorker) {
|
|
||||||
cluster.worker.kill();
|
|
||||||
} else {
|
|
||||||
process.exit(0);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
throw err;
|
process.exit(0);
|
||||||
}
|
}
|
||||||
});
|
} else {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
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');
|
||||||
@@ -123,18 +125,18 @@ if(nconf.get('ssl')) {
|
|||||||
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();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user