Permalink
Browse files

options for start command

  • Loading branch information...
1 parent e149164 commit 7fa6d927effbd7aded0e16e2cf785b6047908b30 @Grigore147 committed Jan 7, 2014
Showing with 35 additions and 11 deletions.
  1. +1 −1 bin/katana
  2. +28 −10 bin/start
  3. +6 −0 lib/cluster.js
View
@@ -63,7 +63,7 @@ if (command==='modules' && !App.args.length) {
App.args.unshift('list');
}
-var proc = spawn(node, [Path.join(modRoot, 'bin', command)].concat(App.args), {
+var proc = spawn(node, [Path.join(modRoot, 'bin', command)].concat(process.argv.slice(3)), {
cwd: root,
stdio: 'inherit'
});
View
@@ -2,22 +2,40 @@
var Path = require('path');
-var App = require('../lib/cluster');
-
var root = process.cwd() + Path.sep;
var cores = require('os').cpus().length;
+function bool(str) {
+ return /^y|yes|ok|true$/i.test(str);
+}
+
+var cmd = require('commander');
+
+cmd
+ .option('-w, --workers <workers>', 'Number of workers')
+ .option('-o, --workon <workon>', 'When a worker should be treated as active [online]')
+ .option('-s, --silent [bool]', 'Share or not stdout/stderr [true]', bool)
+ .option('-l, --signals [bool]', 'Listen process signals [true]', bool)
+ .option('-r, --respawn [bool]', 'Respawn died workers [true]', bool)
+ .option('-t, --timeout', 'Timeout before respawn a worker [2000]', parseInt)
+ .option('-f, --force', 'Timeout for worker to gracefull shutdown [5000]', parseInt)
+.parse(process.argv);
+
+var App = require('../lib/cluster');
App.start({
- script: root +'app.js',
- workers: 2,
- env: null,
- args: ['--https', 'false'],
- workon: 'online',
- silent: true,
- signals: true,
- respawn: true,
+ script: cmd.args[0] || (root +'app.js'),
+ env: null,
+ args: [],
+
+ workers: cmd.workers || cores,
+ workon: cmd.workon || 'online',
+ silent: cmd.silent!==undefined ? cmd.silent : true,
+ signals: cmd.signals!==undefined ? cmd.signals : true,
+ respawn: cmd.respawn!==undefined ? cmd.respawn : true,
+
respawnTimeout: 2000,
forceTimeout: 5000,
+
repl: false
}, function() {
console.log('['+ process.pid +']:', 'cluster online with', this.size, 'workers.');
View
@@ -1,4 +1,5 @@
var Path = require('path');
+var Fs = require('fs');
var EventEmitter = require('events').EventEmitter;
@@ -43,6 +44,11 @@ module.exports = {
this.options = options = conf;
this.set(options);
+ if (!Fs.existsSync(options.script)) {
+ console.error(' Error:', 'script doesn\'t exists!');
+ process.exit(1);
+ }
+
cluster.setupMaster({
exec: options.script,
env: options.env,

0 comments on commit 7fa6d92

Please sign in to comment.