pm2
是全新开发的进程守护服务, 同时集成了负载均衡功能. 以及开机启动, 自动重启有问题进程. 还可以查看各服务进程状态.
使用方法参照:https://github.com/Unitech/pm2
安装:
$ npm install pm2@latest -g
y@y:ydkt$ pm2 start server/app.js -i
[PM2] Process server/app.js launched
┌──────────┬────┬─────────┬───────┬────────┬─────────┬────────┬─────────────┬──────────┐
│ App name │ id │ mode │ pid │ status │ restart │ uptime │ memory │ watching │
├──────────┼────┼─────────┼───────┼────────┼─────────┼────────┼─────────────┼──────────┤
│ app │ │ cluster │ │ online │ │ 0s │ 28.398 MB │ disabled │
│ app │ │ cluster │ │ online │ │ 0s │ 34.203 MB │ disabled │
│ app │ │ cluster │ │ online │ │ 0s │ 27.977 MB │ disabled │
│ app │ │ cluster │ │ online │ │ 0s │ 20.570 MB │ disabled │
└──────────┴────┴─────────┴───────┴────────┴─────────┴────────┴─────────────┴──────────┘
Use `pm2 show <id|name>` to get more details about an app
y@y:ydkt$ pm2 list
┌──────────┬────┬─────────┬───────┬────────┬─────────┬────────┬─────────────┬──────────┐
│ App name │ id │ mode │ pid │ status │ restart │ uptime │ memory │ watching │
├──────────┼────┼─────────┼───────┼────────┼─────────┼────────┼─────────────┼──────────┤
│ app │ │ cluster │ │ online │ │ 5m │ 61.953 MB │ disabled │
│ app │ │ cluster │ │ online │ │ 5m │ 63.715 MB │ disabled │
│ app │ │ cluster │ │ online │ │ 5m │ 61.867 MB │ disabled │
│ app │ │ cluster │ │ online │ │ 5m │ 59.648 MB │ disabled │
└──────────┴────┴─────────┴───────┴────────┴─────────┴────────┴─────────────┴──────────┘
Use `pm2 show <id|name>` to get more details about an app
y@y:ydkt$
y@y:ydkt$ pm2 stop app
[PM2] Stopping app
[PM2] stopProcessId process id
[PM2] stopProcessId process id
[PM2] stopProcessId process id
[PM2] stopProcessId process id
┌──────────┬────┬─────────┬─────┬─────────┬─────────┬────────┬────────┬──────────┐
│ App name │ id │ mode │ pid │ status │ restart │ uptime │ memory │ watching │
├──────────┼────┼─────────┼─────┼─────────┼─────────┼────────┼────────┼──────────┤
│ app │ │ cluster │ │ stopped │ │ │ B │ disabled │
│ app │ │ cluster │ │ stopped │ │ │ B │ disabled │
│ app │ │ cluster │ │ stopped │ │ │ B │ disabled │
│ app │ │ cluster │ │ stopped │ │ │ B │ disabled │
└──────────┴────┴─────────┴─────┴─────────┴─────────┴────────┴────────┴──────────┘
Use `pm2 show <id|name>` to get more details about an app
y@y:ydkt$
参考:http://se77en.cc/2013/06/27/goodbye-node-forever-hello-pm2-translation/