pm2是针对nodejs的项目进程管理工具,可以方便管理多个nodejs进程。
常用命令:
启动
- pm2 start process.js 启动node项目
- pm2 start process.js --name myapp 启动node项目并将命名为myapp
查看进程
- pm2 list
- pm2 show 0
停止
- pm2 stop all 停止所有
- pm2 stop 0 停止id为0的进程
重启
- pm2 restart all
- pm2 restart 0
删除
- pm2 delete all
- pm2 delete 0
查看日志
- pm2 logs 0 [--lines 80] 查看id为0的日志,80行日志
自定义启动文件
{
"apps" : [{
"name" : "sqs-business-alpha",
"script" : "bin/www",
"watch" : ["./routes", "./modules", "app"],
"env" : {
"ENV": "alpha",
"BRANCH": "sqs-business",
"PORT": 3026
},
"error_file" : "./logs/pm2.err.log",
"out_file" : "./logs/pm2.out.log",
"log_date_format" : "YYYY-MM-DD HH:mm Z"
}]
}