better integration with nodebb executable

v1.18.x
Julian Lam 11 years ago
parent 0b2df849bd
commit fec3ae7e5e

@ -4,13 +4,14 @@ var nconf = require('nconf'),
fs = require('fs'), fs = require('fs'),
cluster = require('cluster'), cluster = require('cluster'),
async = require('async'), async = require('async'),
pidFilePath = __dirname + '/pidfile',
output = fs.openSync(__dirname + '/logs/output.log', 'a'),
numCPUs = require('os').cpus().length; numCPUs = require('os').cpus().length;
/* TODO /* TODO
* pidFile and reset timer * pidFile and reset timer
* logging * logging
* restart signal from child * restart signal from child
* minifier
*/ */
// pidFilePath = __dirname + '/pidfile', // pidFilePath = __dirname + '/pidfile',
@ -100,11 +101,9 @@ var Loader = {
}; };
Loader.init = function() { Loader.init = function() {
nconf.argv();
cluster.setupMaster({ cluster.setupMaster({
exec: "app.js", exec: "app.js",
silent: process.env.NODE_ENV !== 'development' ? true : false silent: false/*process.env.NODE_ENV !== 'development' ? true : false*/
}); });
cluster.on('fork', function(worker) { cluster.on('fork', function(worker) {
@ -209,6 +208,26 @@ Loader.reload = function() {
}); });
}; };
nconf.argv();
if (nconf.get('daemon') !== false) {
if (fs.existsSync(pidFilePath)) {
try {
var pid = fs.readFileSync(pidFilePath, { encoding: 'utf-8' });
process.kill(pid, 0);
process.exit();
} catch (e) {
fs.unlinkSync(pidFilePath);
}
}
require('daemon')({
stdout: output
});
fs.writeFile(__dirname + '/pidfile', process.pid);
}
Loader.init(); Loader.init();
// Start the daemon! // Start the daemon!

Loading…
Cancel
Save