mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-12-24 09:20:32 +01:00
fixed #1222
This commit is contained in:
39
loader.js
39
loader.js
@@ -5,9 +5,16 @@ var nconf = require('nconf'),
|
||||
pidFilePath = __dirname + '/pidfile',
|
||||
start = function() {
|
||||
var fork = require('child_process').fork,
|
||||
// output = fs.openSync(__dirname + '/logs/output.log', 'a'),
|
||||
output = fs.createWriteStream(__dirname + '/logs/output.log', {
|
||||
flags: 'a',
|
||||
encoding: 'utf-8'
|
||||
}),
|
||||
nbb_start = function() {
|
||||
var silent = nconf.get('daemon') !== false;
|
||||
|
||||
if (timesStarted > 3) {
|
||||
console.log('\n[loader] Experienced three start attempts in 10 seconds, most likely am error on startup. Halting.');
|
||||
console.log('\n[loader] Experienced three start attempts in 10 seconds, most likely an error on startup. Halting.');
|
||||
return nbb_stop();
|
||||
}
|
||||
|
||||
@@ -20,13 +27,29 @@ var nconf = require('nconf'),
|
||||
nbb = fork('./app', process.argv.slice(2), {
|
||||
env: {
|
||||
'NODE_ENV': process.env.NODE_ENV
|
||||
}
|
||||
},
|
||||
silent: silent
|
||||
});
|
||||
|
||||
|
||||
if (silent) {
|
||||
nbb.stdout.pipe(output);
|
||||
nbb.stderr.pipe(output);
|
||||
}
|
||||
|
||||
nbb.on('message', function(message) {
|
||||
if (message && typeof message === 'object' && message.action) {
|
||||
if (message.action === 'restart') {
|
||||
nbb_restart();
|
||||
} else if (message.action === 'ready' && silent) {
|
||||
// Output bind_address
|
||||
process.stdout.write('\nNodeBB listening on ' + message.bind_address + '\n\n');
|
||||
|
||||
// Daemonize and record new pid
|
||||
require('daemon')({
|
||||
stdout: output
|
||||
});
|
||||
fs.writeFile(__dirname + '/pidfile', process.pid);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -89,19 +112,7 @@ if (nconf.get('daemon') !== false) {
|
||||
}
|
||||
}
|
||||
|
||||
// Initialise logging streams
|
||||
var outputStream = fs.createWriteStream(__dirname + '/logs/output.log');
|
||||
outputStream.on('open', function(fd) {
|
||||
// Daemonize
|
||||
require('daemon')({
|
||||
stdout: fd
|
||||
});
|
||||
|
||||
// Write its pid to a pidfile
|
||||
fs.writeFile(__dirname + '/pidfile', process.pid);
|
||||
|
||||
start();
|
||||
});
|
||||
} else {
|
||||
start();
|
||||
}
|
||||
|
||||
@@ -108,9 +108,17 @@ if(nconf.get('ssl')) {
|
||||
});
|
||||
|
||||
emitter.on('templates:compiled', function() {
|
||||
winston.info('NodeBB attempting to listen on: ' + ((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);
|
||||
|
||||
server.listen(port, nconf.get('bind_address'), function(){
|
||||
winston.info('NodeBB Ready');
|
||||
if (process.send) {
|
||||
process.send({
|
||||
action: 'ready',
|
||||
bind_address: bind_address
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user