From 59b3e6f78fdcdb4dfbded9d65dfd58e08c0a6355 Mon Sep 17 00:00:00 2001 From: psychobunny <psycho.bunny@hotmail.com> Date: Fri, 17 Oct 2014 01:42:55 -0400 Subject: [PATCH] reverting #2259 temporarily until we figure out why logs aren't showing up --- app.js | 32 ++++++++++++-------------- loader.js | 69 +++++++++++++++++-------------------------------------- 2 files changed, 36 insertions(+), 65 deletions(-) diff --git a/app.js b/app.js index 3b02134831..441b3846e2 100644 --- a/app.js +++ b/app.js @@ -58,13 +58,11 @@ if(os.platform() === 'linux') { }); } -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(''); -} +// 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'), @@ -104,20 +102,20 @@ function loadConfig() { } function start() { + loadConfig(); - if (!cluster.isWorker) { - winston.info('Time: ' + new Date()); - winston.info('Initializing NodeBB v' + pkg.version); - winston.info('* using configuration stored in: ' + configFile); - } + 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 && 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') : '') : ''; + winston.info('* using ' + nconf.get('database') +' store ' + storeLocation); + winston.info('* using themes stored in: ' + nconf.get('themes_path')); - winston.info('* using ' + nconf.get('database') +' store ' + storeLocation); - winston.info('* using themes stored in: ' + nconf.get('themes_path')); + if (process.env.NODE_ENV === 'development') { + winston.info('Base Configuration OK.'); } require('./src/database').init(function(err) { diff --git a/loader.js b/loader.js index 7e63804175..c1603278fe 100644 --- a/loader.js +++ b/loader.js @@ -6,14 +6,10 @@ 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, - numProcs, - + numCPUs, Loader = { timesStarted: 0, shutdown_queue: [], @@ -27,7 +23,7 @@ var nconf = require('nconf'), } }; -Loader.init = function(callback) { +Loader.init = function() { cluster.setupMaster({ exec: "app.js", silent: silent @@ -40,20 +36,6 @@ Loader.init = function(callback) { }; } - 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) { @@ -133,7 +115,7 @@ Loader.addClusterEvents = function(callback) { case 'user:connect': case 'user:disconnect': case 'config:update': - Loader.notifyWorkers(message); + notifyWorkers(message); break; } } @@ -144,9 +126,15 @@ Loader.addClusterEvents = function(callback) { 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 < numProcs*3) { + if (Loader.timesStarted < numCPUs*3) { Loader.timesStarted++; if (Loader.crashTimer) { clearTimeout(Loader.crashTimer); @@ -155,7 +143,7 @@ Loader.addClusterEvents = function(callback) { Loader.timesStarted = 0; }); } else { - console.log(numProcs*3 + ' restarts in 10 seconds, most likely an error on startup. Halting.'); + console.log(numCPUs*3 + ' restarts in 10 seconds, most likely an error on startup. Halting.'); process.exit(); } } @@ -171,16 +159,16 @@ Loader.addClusterEvents = function(callback) { } }); - callback(); -} + process.on('SIGHUP', Loader.restart); + + Loader.start(); +}; -Loader.start = function(callback) { +Loader.start = function() { var output = logrotate({ file: __dirname + '/logs/output.log', size: '1m', keep: 3, compress: true }), worker; - console.log('Clustering enabled: Spinning up ' + numProcs + ' process(es).\n'); - - for(var x=0;x<numProcs;x++) { + for(var x=0;x<numCPUs;x++) { // Only the first worker sets up templates/sounds/jobs/etc worker = cluster.fork({ cluster_setup: x === 0, @@ -192,8 +180,6 @@ Loader.start = function(callback) { worker.process.stdout.pipe(output); } } - - if (callback) callback(); }; Loader.restart = function(callback) { @@ -210,19 +196,15 @@ Loader.reload = function() { }); }; -Loader.notifyWorkers = function (msg) { - Object.keys(cluster.workers).forEach(function(id) { - cluster.workers[id].send(msg); - }); -} + nconf.argv().file({ file: path.join(__dirname, '/config.json') }); -numProcs = nconf.get('cluster') || 1; -numProcs = (numProcs === true) ? require('os').cpus().length : numProcs; +numCPUs = nconf.get('cluster') || 1; +numCPUs = (numCPUs === true) ? require('os').cpus().length : numCPUs; if (nconf.get('daemon') !== false) { if (fs.existsSync(pidFilePath)) { @@ -240,13 +222,4 @@ if (nconf.get('daemon') !== false) { fs.writeFile(__dirname + '/pidfile', process.pid); } -async.series([ - Loader.init, - Loader.displayStartupMessages, - Loader.addClusterEvents, - Loader.start -], function(err) { - if (err) { - console.log('[loader] Error during startup: ' + err.message); - } -}); \ No newline at end of file +Loader.init();