[Goodbye node-forever, hello PM2][pm2] [pm2]: (http://devo.ps/blog/2013/06/26/goodbye-node-forever-hello-pm2.html)
看了工具的介绍, 觉得蛮方便的, 就是不支持 CoffeeScript 让人有点抓狂:
Github: https://github.com/Unitech/pm2
npm install -g pm2
特点
PM2 觉得 Forever 有一些不好用的地方:
- log 和监视的功能有限
- 进程和集群管理有限
- Aging codebase (升级 Node 容易导致应用失败)
目测比 Forever 好用一些… PM2 是前几个月刚写的, 还不完善: 列出来的计划有:
- Remote administration/status checking,
- Built-in inter-processes communication channel (message bus),
- V8 GC 内存泄露检测,
- Web 界面,
- Persistent storage for monitoring data,
- 邮件通知
Demo
盗链个截图:
然后本地安装尝试了一下:
➤➤ cat a.js
// Generated by CoffeeScript 1.6.3
require('http').createServer(function(req, res) {
return res.end('ok');
}).listen(3000);
➤➤ pm2 start a.js
⌬ PM2 Configuration : { script: 'a.js', name: 'a' }
⌬ PM2 You can write the current configuration by adding -w option
⌬ PM2 Process launched
┌────────┬────┬───────┬────────┬───────────┬─────────────────────┬──────────┬────────────────────────────────┐
│ Script │ id │ PID │ status │ Restarted │ Last restart │ memory │ err logs │
├────────┼────┼───────┼────────┼───────────┼─────────────────────┼──────────┼────────────────────────────────┤
│ a.js │ 0 │ 27515 │ online │ 0 │ 2013-06-27 14:16:28 │ 8.469 MB │ /home/yong/.pm2/logs/a-err.log │
➤➤ pm2 list
⌬ PM2 Process listing
┌────────┬────┬───────┬────────┬───────────┬─────────────────────┬───────────┬────────────────────────────────┐
│ Script │ id │ PID │ status │ Restarted │ Last restart │ memory │ err logs │
├────────┼────┼───────┼────────┼───────────┼─────────────────────┼───────────┼────────────────────────────────┤
│ a.js │ 0 │ 27515 │ online │ 0 │ 2013-06-27 14:16:28 │ 10.102 MB │ /home/yong/.pm2/logs/a-err.log │
└────────┴────┴───────┴────────┴───────────┴─────────────────────┴───────────┴────────────────────────────────┘
⌬ PM2 PM2 log file path : /home/yong/.pm2/pm2.log (type pm2 logs to see log streaming)
⌬ PM2 monitoring :
a.js [27515] [ ] 0 %
[||| ] 10.102 MB
➤➤ pm2 kill
Daemon killed
➤➤ pm2 logs
Launching daemon
{ online: true, success: true, pid: 27553 }
[PM2 DAEMON (l0)] "/opt/s/demo/a.coffee -省略省略...
12 回复
在Windows 7下一次就安装成功,爽了一下,于是运行看看:
Microsoft Windows [版本 6.1.7601]
版权所有 (c) 2009 Microsoft Corporation。保留所有权利。
x:\>pm2 list
path.js:116
throw new TypeError('Arguments to path.resolve must be strings');
^
TypeError: Arguments to path.resolve must be strings
at Object.exports.resolve (path.js:116:15)
at Object.<anonymous> (C:\Users\ooxx\AppData\Roaming\npm\node_modules\pm2\constants.js:8:23)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (C:\Users\ooxx\AppData\Roaming\npm\node_modules\pm2\lib\Satan.js:11:11)
at Module._compile (module.js:456:26)
多么痛的领悟…