|
@@ -86,3 +86,144 @@ pm2 startup
|
|
|
```
|
|
|
|
|
|
参考官方文档获取详细使用说明。
|
|
|
+
|
|
|
+
|
|
|
+## 自动重启
|
|
|
+
|
|
|
+设置内存使用过高上限,可以通过配置文件这一项:
|
|
|
+
|
|
|
+```js
|
|
|
+{
|
|
|
+ "max_memory_restart": "800M"
|
|
|
+}
|
|
|
+```
|
|
|
+
|
|
|
+如果想要根据CPU使用过高自动重启,则稍微麻烦点,需要自己写一个脚本监控。
|
|
|
+
|
|
|
+```bash
|
|
|
+pm2 jlist
|
|
|
+```
|
|
|
+
|
|
|
+结果会是这样的json:
|
|
|
+
|
|
|
+```json
|
|
|
+[
|
|
|
+ {
|
|
|
+ "pid": 28701,
|
|
|
+ "name": "xxxx",
|
|
|
+ "pm2_env": {
|
|
|
+ "name": "xxxx",
|
|
|
+ "max_memory_restart": 838860800,
|
|
|
+ "instances": 0,
|
|
|
+ "cwd": "/xxxx/project",
|
|
|
+ "merge_logs": true,
|
|
|
+ "vizion": true,
|
|
|
+ "pmx": true,
|
|
|
+ "automation": true,
|
|
|
+ "autorestart": true,
|
|
|
+ "treekill": true,
|
|
|
+ "env": {
|
|
|
+ "PM2_JSON_PROCESSING": "true",
|
|
|
+ "LSCOLORS": "Gxfxcxdxbxegedabagacad",
|
|
|
+ "LESS": "-R",
|
|
|
+ "PAGER": "less",
|
|
|
+ "SSH_TTY": "/dev/pts/1",
|
|
|
+ "SSH_CLIENT": "218.94.29.190 53115 22",
|
|
|
+ "SHELL": "/bin/bash",
|
|
|
+ "TERM": "xterm-256color",
|
|
|
+ "XDG_SESSION_ID": "814",
|
|
|
+ "NODE_ENV": "production",
|
|
|
+ "max_memory_restart": 838860800,
|
|
|
+ "instances": 0,
|
|
|
+ "merge_logs": true,
|
|
|
+ "vizion": true,
|
|
|
+ "pmx": true,
|
|
|
+ "automation": true,
|
|
|
+ "autorestart": true,
|
|
|
+ "treekill": true,
|
|
|
+ "log_date_format": "YYYY-MM-DD HH:mm:ss Z",
|
|
|
+ "exec_mode": "cluster_mode",
|
|
|
+ "node_args": [],
|
|
|
+ "exec_interpreter": "node",
|
|
|
+ "pm_out_log_path": "/xxxxx/logs/fish.out.log",
|
|
|
+ "pm_err_log_path": "/xxxxx/logs/fish.err.log"
|
|
|
+ },
|
|
|
+ "log_date_format": "YYYY-MM-DD HH:mm:ss Z",
|
|
|
+ "exec_mode": "cluster_mode",
|
|
|
+ "node_args": [],
|
|
|
+ "pm_exec_path": "/xxxx/babel.js",
|
|
|
+ "pm_cwd": "/xxxxx/project",
|
|
|
+ "exec_interpreter": "node",
|
|
|
+ "pm_out_log_path": "/xxxxxx/xxx.out.log",
|
|
|
+ "pm_err_log_path": "/xxxxxx/xxx.err.log",
|
|
|
+ "NODE_APP_INSTANCE": 0,
|
|
|
+ "vizion_running": false,
|
|
|
+ "PM2_JSON_PROCESSING": "true",
|
|
|
+ "LESSCLOSE": "/usr/bin/lesspipe %s %s",
|
|
|
+ "XDG_RUNTIME_DIR": "/run/user/1000",
|
|
|
+ "LESSOPEN": "| /usr/bin/lesspipe %s",
|
|
|
+ "LC_CTYPE": "zh_CN.UTF-8",
|
|
|
+ "SSH_TTY": "/dev/pts/1",
|
|
|
+ "SHELL": "/bin/bash",
|
|
|
+ "NODE_ENV": "production",
|
|
|
+ "fish": "{}",
|
|
|
+ "status": "online",
|
|
|
+ "pm_uptime": 1472561001434,
|
|
|
+ "axm_actions": [],
|
|
|
+ "axm_monitor": {
|
|
|
+ "Loop delay": {
|
|
|
+ "value": "0.92ms",
|
|
|
+ "agg_type": "avg",
|
|
|
+ "alert": {}
|
|
|
+ }
|
|
|
+ },
|
|
|
+ "axm_options": {
|
|
|
+ "http": false,
|
|
|
+ "http_latency": 200,
|
|
|
+ "http_code": 500,
|
|
|
+ "ignore_routes": [],
|
|
|
+ "profiling": true,
|
|
|
+ "errors": true,
|
|
|
+ "alert_enabled": true,
|
|
|
+ "custom_probes": true,
|
|
|
+ "network": false,
|
|
|
+ "ports": false,
|
|
|
+ "module_conf": {},
|
|
|
+ "module_name": "fish",
|
|
|
+ "module_version": "1.1.3",
|
|
|
+ "pmx_version": "0.6.2",
|
|
|
+ "error": true
|
|
|
+ },
|
|
|
+ "axm_dynamic": {},
|
|
|
+ "created_at": 1472561000966,
|
|
|
+ "pm_id": 3,
|
|
|
+ "restart_time": 1,
|
|
|
+ "unstable_restarts": 0,
|
|
|
+ "_pm2_version": "1.1.3",
|
|
|
+ "versioning": {
|
|
|
+ "type": "git",
|
|
|
+ "update_time": "2016-09-02T07:25:14.113Z",
|
|
|
+ "comment": "v3.6.12 - fix-importer",
|
|
|
+ "unstaged": false,
|
|
|
+ "branch": "HEAD",
|
|
|
+ "remotes": [
|
|
|
+ "origin"
|
|
|
+ ],
|
|
|
+ "remote": "origin",
|
|
|
+ "branch_exists_on_remote": true,
|
|
|
+ "ahead": false,
|
|
|
+ "next_rev": null
|
|
|
+ },
|
|
|
+ "node_version": "6.3.0",
|
|
|
+ "exit_code": 0
|
|
|
+ },
|
|
|
+ "pm_id": 3,
|
|
|
+ "monit": {
|
|
|
+ "memory": 90591232,
|
|
|
+ "cpu": 0
|
|
|
+ }
|
|
|
+ }
|
|
|
+]
|
|
|
+```
|
|
|
+
|
|
|
+其中每一列数据都有 `rows[i].monit.cpu`,值范围 0~100。可以用`later`写定时脚本监控并重启。
|