reverting #2259 temporarily until we figure out why logs aren't showing up

This commit is contained in:
psychobunny
2014-10-17 01:42:55 -04:00
parent 3ba4d2aa2b
commit 59b3e6f78f
2 changed files with 36 additions and 65 deletions

View File

@@ -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 = function(callback) {
Loader.start();
};
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);
}
});
Loader.init();