You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/source/en/core/deployment.md
+41-30Lines changed: 41 additions & 30 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -27,37 +27,49 @@ Reusable package brings a few pros in:
27
27
28
28
Node.js(`>= 6.0.0`) is required so that you should make sure it is pre-installed in runtime environment.
29
29
30
-
Egg takes `egg-cluster` to create [Master](https://github.com/eggjs/egg/blob/master/docs/source/en/core/cluster-and-ipc.md#master) process, which you can rely on to secure the application instead of daemon manager like [pm2](https://github.com/Unitech/pm2). The API is also really convenient for developers to achieve that, just `egg.startCluster`.
30
+
Egg takes `egg-cluster` to create [Master](https://github.com/eggjs/egg/blob/master/docs/source/en/core/cluster-and-ipc.md#master) process, which you can rely on to secure the application instead of daemon manager like [pm2]. The API is also really convenient for developers to achieve that, just `egg.startCluster`.
31
31
32
-
More about [egg-cluster](https://github.com/eggjs/egg-cluster#options)
32
+
And framework also provide [egg-scripts] for developers to start/stop application at prod mode.
33
33
34
-
### Dispatch file
34
+
Firstly, we need to import `egg-scripts` as `dependencies`:
35
35
36
-
Create a new dispatch file in the root directory, for instance `dispatch.js`:
36
+
```bash
37
+
$ npm i egg-scripts --save
38
+
```
37
39
38
-
```js
39
-
// dispatch.js
40
-
constegg=require('egg');
40
+
Then add `npm scripts` to `package.json`:
41
41
42
-
egg.startCluster({
43
-
baseDir:__dirname,
44
-
});
42
+
```json
43
+
{
44
+
"scripts": {
45
+
"start": "egg-scripts start --daemon",
46
+
"stop": "egg-scripts stop"
47
+
}
48
+
}
45
49
```
46
50
47
-
### Dispatch in background
51
+
Then we are able to use `npm start` and `npm stop` to manage application.
52
+
53
+
> Note: `egg-scripts` don't support Windows.
48
54
49
-
Once you create dispatch file, you can launch the application and redirect standard output to `stdout.log` as well as error details to `stderr.log`, which are really useful for debugging later.
-`EGG_SERVER_ENV` in production must be `prod`, for more information about [runtime environment](https://github.com/eggjs/egg/blob/master/docs/source/en/basics/env.md).
57
-
- Launching directly when the application run in docker instance.
58
-
- Egg usually initialize instances as many as cores, which can leverage the capability of the cpu.
61
+
Options:
62
+
63
+
-`--port=7001` http server port, will use `process.env.PORT`, default to `7001`.
64
+
-`--daemon` whether run at background, so you don't need `nohup`. Ignore this when the application run in docker instance.
65
+
-`--env=prod` then framework env, will use `process.env.EGG_SERVER_ENV`, default to `prod`。
66
+
-`--workers=2` worker count, default to cpu cores, which can leverage the capability of the cpu.
67
+
-`--title=egg-server-showcase` convenient for `ps + grep`, default to `egg-server-${appname}`.
68
+
-`--framework=yadan` config `egg.framework` at `package.json` or pass this args, when you are using [Custom Framework](../advanced/framework.md).
59
69
60
-
### Dispatch with arguments
70
+
More about [egg-scripts] and [egg-cluster] documents.
71
+
72
+
#### Dispatch with arguments
61
73
62
74
Arguments of dispatch can be configured in `config.{env}.js`.
63
75
@@ -74,17 +86,16 @@ exports.cluster = {
74
86
75
87
[server.listen](https://nodejs.org/api/http.html#http_server_listen_port_hostname_backlog_callback) supports arguments including `path`, `port` and `hostname` to change dispatching behavior. One thing you should know is that the `port` in `egg.startCluster` will override the one in application config.
76
88
77
-
### Dispatch from extended framework
89
+
### Stop
90
+
91
+
```bash
92
+
$ egg-scripts stop
93
+
```
94
+
95
+
This command will kill master process which will handler and notice worker and agent to gracefull exit.
78
96
79
-
What about dispatch from your framework extended from [Egg's Application](https://github.com/eggjs/egg/blob/master/docs/source/en/advanced/framework.md) like `yadan`? Egg offers `customEgg` to change the entry:
97
+
Also you can manually call `ps -eo "pid,command" | grep "--type=egg-server"` to find master process then `kill` without `-9`.
0 commit comments