diff --git a/.gitignore b/.gitignore index 6e3a9a82..d7987c7e 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ node_modules/ coverage/ !test/fixtures/custom-framework-app/node_modules/ .tmp +.vscode diff --git a/README.md b/README.md index a7107dfb..64c942c6 100644 --- a/README.md +++ b/README.md @@ -64,8 +64,9 @@ $ egg-bin dev - `--eggPath` egg web framework root path.No default value, must supply. - `--baseDir` application's root path.default to `process.cwd()`. -- `--port` server port.default to 7001. -- `--cluster` worker process number.default to 1. +- `--port` server port.default to `7001`. +- `--cluster` worker process number.default to `1`. +- `--sticky` start a sticky cluster server.default to `false`. ### debug diff --git a/README.zh-CN.md b/README.zh-CN.md index f9334047..6786cd27 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -60,6 +60,14 @@ $ npm i egg-bin --save-dev $ egg-bin dev ``` +##### options + +- `--eggPath` egg web 框架根目录。必须设置。 +- `--baseDir` 应用根目录,默认为 `process.cwd()`。 +- `--port` 服务端口,默认为 `7001`。 +- `--cluster` 工作进程数量。默认为 `1`. +- `--sticky` 启动 `sticky` 模式服务。默认为 `false`。 + ### debug 使用 iron-node 调试工具启动应用。 diff --git a/lib/start-cluster b/lib/start-cluster index d3373c60..c2bc99dd 100755 --- a/lib/start-cluster +++ b/lib/start-cluster @@ -11,6 +11,7 @@ commander .option('--baseDir [baseDir]') .option('-p, --port [port]') .option('--cluster [workers]') + .option('--sticky') .allowUnknownOption(true) .parse(process.argv); @@ -18,6 +19,7 @@ const baseDir = commander.baseDir; const workers = commander.cluster ? Number(commander.cluster) : 1; const port = commander.port; const customEgg = commander.eggPath; +const sticky = commander.sticky; assert(customEgg, 'eggPath required, missing any egg frameworks?'); @@ -26,6 +28,7 @@ const options = { workers, port, customEgg, + sticky, }; debug('eggPath:%s options:%j', customEgg, options); diff --git a/test/egg-dev.test.js b/test/egg-dev.test.js index e2084cea..5535b7b2 100644 --- a/test/egg-dev.test.js +++ b/test/egg-dev.test.js @@ -25,6 +25,13 @@ describe('egg-bin dev', () => { .end(done); }); + it('should startCluster with --sticky', done => { + coffee.fork(eggBin, [ 'dev', '--port', '6001', '--sticky' ], { cwd: appdir }) + .expect('stdout', `{"baseDir":"${appdir}","workers":1,"port":"6001","customEgg":"${customEgg}","sticky":true}\n`) + .expect('code', 0) + .end(done); + }); + it('should startCluster with -p', done => { coffee.fork(eggBin, [ 'dev', '-p', '6001' ], { cwd: appdir }) // .debug()