From 2b401ef2cd31e695119d5a63f871e43d83500f3a Mon Sep 17 00:00:00 2001 From: shaoshuai0102 Date: Mon, 13 Feb 2017 19:45:56 +0800 Subject: [PATCH] doc: add faq - how to start with pm2 --- docs/source/faq.md | 23 +++++++++++++++++++++++ docs/source/zh-cn/faq.md | 19 +++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/docs/source/faq.md b/docs/source/faq.md index 2cd27f8fe4..1f1573e96f 100644 --- a/docs/source/faq.md +++ b/docs/source/faq.md @@ -11,3 +11,26 @@ If you have questions that is not contained below, please check [egg issues](htt Process management is very important. It defines the way we write code, meanwhile relates to deep runtime optimization. So we think it's better defined by framework itself. +## How to start application with PM2? + +Although PM2 is not recommanded, you can use it anyway. + +Firstly, put a start file in the root directory of your project: + +```js +// server.js +const egg = require('egg'); + +const workers = Number(process.argv[2] || require('os').cpus().length); +egg.startCluster({ + workers, + baseDir: __dirname, +}); +``` + +We can start application with PM2 like this: + +```bash +pm2 start server.js +``` + diff --git a/docs/source/zh-cn/faq.md b/docs/source/zh-cn/faq.md index 89df21c3c0..7b1586c3f7 100644 --- a/docs/source/zh-cn/faq.md +++ b/docs/source/zh-cn/faq.md @@ -11,6 +11,25 @@ title: 常见问题 进程模型非常重要,会影响到开发模式,运行期间的深度优化等,我们认为可能由框架来控制比较合适。 +## 如何使用 PM2 启动应用? +尽管我们不推荐使用 PM2 启动,但仍然是可以做到的。 +首先,在项目根目录定义启动文件: +```js +// server.js +const egg = require('egg'); + +const workers = Number(process.argv[2] || require('os').cpus().length); +egg.startCluster({ + workers, + baseDir: __dirname, +}); +``` + +这样,我们就可以通过 PM2 进行启动了: + +```bash +pm2 start server.js +```