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