From 8ef4ad6f148bb3f26614f811123e04a3f55a7415 Mon Sep 17 00:00:00 2001 From: psychobunny Date: Fri, 17 Oct 2014 01:47:13 -0400 Subject: [PATCH] Revert "reverting #2259 temporarily until we figure out why logs aren't showing up" This reverts commit 59b3e6f78fdcdb4dfbded9d65dfd58e08c0a6355. --- app.js | 32 ++++++++++++++------------ loader.js | 69 ++++++++++++++++++++++++++++++++++++++----------------- 2 files changed, 65 insertions(+), 36 deletions(-) diff --git a/app.js b/app.js index 441b3846e2..3b02134831 100644 --- a/app.js +++ b/app.js @@ -58,11 +58,13 @@ if(os.platform() === 'linux') { }); } -// Log GNU copyright info along with server info -winston.info('NodeBB v' + pkg.version + ' Copyright (C) 2013-2014 NodeBB Inc.'); -winston.info('This program comes with ABSOLUTELY NO WARRANTY.'); -winston.info('This is free software, and you are welcome to redistribute it under certain conditions.'); -winston.info(''); +if (!cluster.isWorker) { + // If run using `node app`, log GNU copyright info along with server info + winston.info('NodeBB v' + pkg.version + ' Copyright (C) 2013-2014 NodeBB Inc.'); + winston.info('This program comes with ABSOLUTELY NO WARRANTY.'); + winston.info('This is free software, and you are welcome to redistribute it under certain conditions.'); + winston.info(''); +} // Alternate configuration file support var configFile = path.join(__dirname, '/config.json'), @@ -102,20 +104,20 @@ function loadConfig() { } function start() { - loadConfig(); - winston.info('Time: ' + new Date()); - winston.info('Initializing NodeBB v' + pkg.version); - winston.info('* using configuration stored in: ' + configFile); - var host = nconf.get(nconf.get('database') + ':host'), - storeLocation = host ? 'at ' + host + (host.indexOf('/') === -1 ? ':' + nconf.get(nconf.get('database') + ':port') : '') : ''; + if (!cluster.isWorker) { + winston.info('Time: ' + new Date()); + winston.info('Initializing NodeBB v' + pkg.version); + winston.info('* using configuration stored in: ' + configFile); + } - winston.info('* using ' + nconf.get('database') +' store ' + storeLocation); - winston.info('* using themes stored in: ' + nconf.get('themes_path')); + if (cluster.isWorker && process.env.cluster_setup === 'true') { + var host = nconf.get(nconf.get('database') + ':host'), + storeLocation = host ? 'at ' + host + (host.indexOf('/') === -1 ? ':' + nconf.get(nconf.get('database') + ':port') : '') : ''; - if (process.env.NODE_ENV === 'development') { - winston.info('Base Configuration OK.'); + winston.info('* using ' + nconf.get('database') +' store ' + storeLocation); + winston.info('* using themes stored in: ' + nconf.get('themes_path')); } require('./src/database').init(function(err) { diff --git a/loader.js b/loader.js index c1603278fe..7e63804175 100644 --- a/loader.js +++ b/loader.js @@ -6,10 +6,14 @@ var nconf = require('nconf'), cluster = require('cluster'), async = require('async'), logrotate = require('logrotate-stream'), + + pkg = require('./package.json'), + pidFilePath = __dirname + '/pidfile', output = logrotate({ file: __dirname + '/logs/output.log', size: '1m', keep: 3, compress: true }), silent = process.env.NODE_ENV !== 'development' ? true : false, - numCPUs, + numProcs, + Loader = { timesStarted: 0, shutdown_queue: [], @@ -23,7 +27,7 @@ var nconf = require('nconf'), } }; -Loader.init = function() { +Loader.init = function(callback) { cluster.setupMaster({ exec: "app.js", silent: silent @@ -36,6 +40,20 @@ Loader.init = function() { }; } + process.on('SIGHUP', Loader.restart); + callback(); +}; + +Loader.displayStartupMessages = function(callback) { + console.log('NodeBB v' + pkg.version + ' Copyright (C) 2013-2014 NodeBB Inc.'); + console.log('This program comes with ABSOLUTELY NO WARRANTY.'); + console.log('This is free software, and you are welcome to redistribute it under certain conditions.'); + console.log('For the full license, please visit: http://www.gnu.org/copyleft/gpl.html'); + console.log(''); + callback(); +}; + +Loader.addClusterEvents = function(callback) { cluster.on('fork', function(worker) { worker.on('message', function(message) { if (message && typeof message === 'object' && message.action) { @@ -115,7 +133,7 @@ Loader.init = function() { case 'user:connect': case 'user:disconnect': case 'config:update': - notifyWorkers(message); + Loader.notifyWorkers(message); break; } } @@ -126,15 +144,9 @@ Loader.init = function() { console.log('[cluster] Child Process (' + worker.process.pid + ') listening for connections.'); }); - function notifyWorkers(msg) { - Object.keys(cluster.workers).forEach(function(id) { - cluster.workers[id].send(msg); - }); - } - cluster.on('exit', function(worker, code, signal) { if (code !== 0) { - if (Loader.timesStarted < numCPUs*3) { + if (Loader.timesStarted < numProcs*3) { Loader.timesStarted++; if (Loader.crashTimer) { clearTimeout(Loader.crashTimer); @@ -143,7 +155,7 @@ Loader.init = function() { Loader.timesStarted = 0; }); } else { - console.log(numCPUs*3 + ' restarts in 10 seconds, most likely an error on startup. Halting.'); + console.log(numProcs*3 + ' restarts in 10 seconds, most likely an error on startup. Halting.'); process.exit(); } } @@ -159,16 +171,16 @@ Loader.init = function() { } }); - process.on('SIGHUP', Loader.restart); - - Loader.start(); -}; + callback(); +} -Loader.start = function() { +Loader.start = function(callback) { var output = logrotate({ file: __dirname + '/logs/output.log', size: '1m', keep: 3, compress: true }), worker; - for(var x=0;x