diff --git a/loader.js b/loader.js index 389412fdef..749d3e619a 100644 --- a/loader.js +++ b/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(); } @@ -18,15 +25,31 @@ var nconf = require('nconf'), startTimer = setTimeout(resetTimer, 1000*10); nbb = fork('./app', process.argv.slice(2), { - env: { - 'NODE_ENV': process.env.NODE_ENV - } - }); + 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(); - }); + start(); } else { start(); } diff --git a/src/webserver.js b/src/webserver.js index 13c3b7a128..a9ffd958b6 100644 --- a/src/webserver.js +++ b/src/webserver.js @@ -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 + }); + } }); }); };