nt-arcane
Version:
App creator for arcane framework.
44 lines (39 loc) • 1.17 kB
JavaScript
const os = require('os');
const cluster = require('cluster'),
stopSignals = [
'SIGHUP', 'SIGINT', 'SIGQUIT', 'SIGILL', 'SIGTRAP', 'SIGABRT',
'SIGBUS', 'SIGFPE', 'SIGUSR1', 'SIGSEGV', 'SIGUSR2', 'SIGTERM'
],
production = process.env.NODE_ENV == 'production';
var stopping = false;
process.stdin.resume();
process.on('uncaughtException', function(err) {
if(err && typeof err !== 'string') {
console.log(err.stack || err);
}
});
cluster.on('disconnect', function(worker) {
console.log('Worker: ended.');
if (!stopping) {
cluster.fork();
}
});
if (cluster.isMaster) {
const workerCount = process.env.NODE_CLUSTER_WORKERS || os.cpus().length;
console.log(`Starting ${workerCount} workers...`);
for (var i = 0; i < workerCount; i++) {
cluster.fork();
}
stopSignals.forEach(function (signal) {
process.on(signal, function () {
console.log(`Got ${signal}, stopping workers...`);
stopping = true;
cluster.disconnect(function () {
console.log('All workers stopped, exiting.');
process.exit(0);
});
});
});
} else {
require('nt-arcane').startApp(__dirname);
}