From 4f2603afd10807779ca37d42a338f7c370eabcea Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Tue, 30 Sep 2014 21:48:39 -0400 Subject: [PATCH] closed #2185 --- loader.js | 29 +++++++++++++++++++++-------- nodebb | 5 ----- package.json | 5 +++-- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/loader.js b/loader.js index 6ae585812f..0119f10f60 100644 --- a/loader.js +++ b/loader.js @@ -5,8 +5,10 @@ var nconf = require('nconf'), path = require('path'), cluster = require('cluster'), async = require('async'), + logrotate = require('logrotate-stream'), pidFilePath = __dirname + '/pidfile', - output = fs.openSync(__dirname + '/logs/output.log', 'a'), + output = logrotate({ file: __dirname + '/logs/output.log', size: '1m', keep: 3, compress: true }), + silent = process.env.NODE_ENV !== 'development' ? true : false, numCPUs, Loader = { timesStarted: 0, @@ -24,9 +26,15 @@ var nconf = require('nconf'), Loader.init = function() { cluster.setupMaster({ exec: "app.js", - silent: false + silent: silent }); + if (silent) { + console.log = function(value) { + output.write(value + '\n'); + }; + } + cluster.on('fork', function(worker) { worker.on('message', function(message) { if (message && typeof message === 'object' && message.action) { @@ -132,7 +140,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(numCPUs*3 + ' restarts in 10 seconds, most likely an error on startup. Halting.'); process.exit(); } } @@ -154,14 +162,21 @@ Loader.init = function() { }; Loader.start = function() { + var worker; + Loader.primaryWorker = 1; for(var x=0;x