From ac9bd0859f2bc1dfa7229d7820ccc2997bf222f2 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Sun, 4 May 2014 16:46:09 -0400 Subject: [PATCH] fixed #1477 --- loader.js | 33 ++++++++------------------------- 1 file changed, 8 insertions(+), 25 deletions(-) diff --git a/loader.js b/loader.js index 749d3e619a..afce4daada 100644 --- a/loader.js +++ b/loader.js @@ -3,16 +3,10 @@ var nconf = require('nconf'), fs = require('fs'), pidFilePath = __dirname + '/pidfile', + output = fs.openSync(__dirname + '/logs/output.log', 'a'), 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 an error on startup. Halting.'); return nbb_stop(); @@ -27,29 +21,13 @@ 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); } } }); @@ -105,13 +83,18 @@ if (nconf.get('daemon') !== false) { try { var pid = fs.readFileSync(pidFilePath, { encoding: 'utf-8' }); process.kill(pid, 0); - console.log('\n Error: Another NodeBB is already running!'); process.exit(); } catch (e) { fs.unlinkSync(pidFilePath); } } + // Daemonize and record new pid + require('daemon')({ + stdout: output + }); + fs.writeFile(__dirname + '/pidfile', process.pid); + start(); } else { start();