v1.18.x
Julian Lam 10 years ago
parent 31db0d78b1
commit 4f2603afd1

@ -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<numCPUs;x++) {
// Only the first worker sets up templates/sounds/jobs/etc
cluster.fork({
worker = cluster.fork({
cluster_setup: x === 0,
handle_jobs: x ===0
handle_jobs: x === 0
});
// Logging
if (silent) {
worker.process.stdout.pipe(output);
}
}
}
@ -200,9 +215,7 @@ if (nconf.get('daemon') !== false) {
}
}
require('daemon')({
stdout: output
});
require('daemon')();
fs.writeFile(__dirname + '/pidfile', process.pid);
}

@ -28,11 +28,6 @@ case "$1" in
echo " \"./nodebb stop\" to stop the NodeBB server";
echo " \"./nodebb log\" to view server output";
if [ -f "./logs/output.log" ]; # Preserve the last output log
then
mv ./logs/output.log ./logs/output.1.log;
fi;
# Start the loader daemon
"$node" loader -d "$@"
;;

@ -31,15 +31,16 @@
"gm": "1.16.0",
"gravatar": "1.0.6",
"less": "~1.7.3",
"logrotate-stream": "^0.2.3",
"mkdirp": "~0.5.0",
"morgan": "^1.0.0",
"nconf": "~0.6.7",
"nodebb-plugin-downvote-post": "^0.1.0",
"nodebb-plugin-upvote-post": "^1.0.0",
"nodebb-plugin-dbsearch": "0.0.13",
"nodebb-plugin-downvote-post": "^0.1.0",
"nodebb-plugin-markdown": "~0.6.3",
"nodebb-plugin-mentions": "~0.6.0",
"nodebb-plugin-soundpack-default": "~0.1.1",
"nodebb-plugin-upvote-post": "^1.0.0",
"nodebb-theme-lavender": "~0.1.0",
"nodebb-theme-vanilla": "~0.1.0",
"nodebb-widget-essentials": "~0.1.1",

Loading…
Cancel
Save