mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-07-08 12:23:35 +02:00
closed #2012
This commit is contained in:
10
app.js
10
app.js
@@ -141,7 +141,13 @@ function start() {
|
||||
nconf.set('url', nconf.get('base_url') + (nconf.get('use_port') ? ':' + nconf.get('port') : '') + nconf.get('relative_path'));
|
||||
|
||||
plugins.ready(function() {
|
||||
webserver.init();
|
||||
webserver.init(function() {
|
||||
// If this callback is called, this means that loader.js is used
|
||||
process.on('SIGCONT', webserver.listen);
|
||||
process.send({
|
||||
action: 'ready'
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
process.on('SIGTERM', shutdown);
|
||||
@@ -313,6 +319,8 @@ function shutdown(code) {
|
||||
winston.info('[app] Shutdown (SIGTERM/SIGINT) Initialised.');
|
||||
require('./src/database').close();
|
||||
winston.info('[app] Database connection closed.');
|
||||
require('./src/webserver').server.close();
|
||||
winston.info('[app] Web server closed to connections.');
|
||||
|
||||
winston.info('[app] Shutdown complete.');
|
||||
process.exit(code || 0);
|
||||
|
||||
29
loader.js
29
loader.js
@@ -5,8 +5,7 @@ var nconf = require('nconf'),
|
||||
pidFilePath = __dirname + '/pidfile',
|
||||
output = fs.openSync(__dirname + '/logs/output.log', 'a'),
|
||||
start = function() {
|
||||
var fork = require('child_process').fork,
|
||||
nbb_start = function() {
|
||||
var nbb_start = function(callback) {
|
||||
if (timesStarted > 3) {
|
||||
console.log('\n[loader] Experienced three start attempts in 10 seconds, most likely an error on startup. Halting.');
|
||||
return nbb_stop();
|
||||
@@ -18,14 +17,24 @@ var nconf = require('nconf'),
|
||||
}
|
||||
startTimer = setTimeout(resetTimer, 1000*10);
|
||||
|
||||
nbb = fork('./app', process.argv.slice(2), {
|
||||
if (nbb) {
|
||||
nbbOld = nbb;
|
||||
}
|
||||
|
||||
nbb = require('child_process').fork('./app', process.argv.slice(2), {
|
||||
env: process.env
|
||||
});
|
||||
|
||||
nbb.on('message', function(message) {
|
||||
if (message && typeof message === 'object' && message.action) {
|
||||
if (message.action === 'restart') {
|
||||
nbb_restart();
|
||||
switch (message.action) {
|
||||
case 'ready':
|
||||
if (!callback) return nbb.kill('SIGCONT');
|
||||
callback();
|
||||
break;
|
||||
case 'restart':
|
||||
nbb_restart();
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -52,10 +61,12 @@ var nconf = require('nconf'),
|
||||
}
|
||||
},
|
||||
nbb_restart = function() {
|
||||
nbb.removeAllListeners('exit').on('exit', function() {
|
||||
nbb_start();
|
||||
nbb_start(function() {
|
||||
nbbOld.removeAllListeners('exit').on('exit', function() {
|
||||
nbb.kill('SIGCONT');
|
||||
});
|
||||
nbbOld.kill();
|
||||
});
|
||||
nbb.kill();
|
||||
},
|
||||
resetTimer = function() {
|
||||
clearTimeout(startTimer);
|
||||
@@ -70,7 +81,7 @@ var nconf = require('nconf'),
|
||||
|
||||
nbb_start();
|
||||
},
|
||||
nbb;
|
||||
nbb, nbbOld;
|
||||
|
||||
nconf.argv();
|
||||
|
||||
|
||||
@@ -97,7 +97,7 @@ if(nconf.get('ssl')) {
|
||||
}
|
||||
|
||||
module.exports.server = server;
|
||||
module.exports.init = function () {
|
||||
module.exports.init = function(callback) {
|
||||
server.on("error", function(err){
|
||||
if (err.code === 'EADDRINUSE') {
|
||||
winston.error('NodeBB address in use, exiting...');
|
||||
@@ -114,18 +114,26 @@ if(nconf.get('ssl')) {
|
||||
});
|
||||
|
||||
emitter.on('templates:compiled', function() {
|
||||
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);
|
||||
if (process.send) {
|
||||
callback();
|
||||
} else {
|
||||
module.exports.listen();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
server.listen(port, nconf.get('bind_address'), function(){
|
||||
winston.info('NodeBB is now listening on: ' + bind_address);
|
||||
if (process.send) {
|
||||
process.send({
|
||||
action: 'ready',
|
||||
bind_address: bind_address
|
||||
});
|
||||
}
|
||||
});
|
||||
module.exports.listen = function() {
|
||||
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);
|
||||
|
||||
server.listen(port, nconf.get('bind_address'), function(){
|
||||
winston.info('NodeBB is now listening on: ' + bind_address);
|
||||
if (process.send) {
|
||||
process.send({
|
||||
action: 'listening',
|
||||
bind_address: bind_address
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user