平時自己簡單用pm2 start管理自己的node進(jìn)程,現(xiàn)在機(jī)器上起了多個進(jìn)程绰上,一個個配置比較麻煩泡垃,今天查到pm2可以啟動一個json配置文件析珊,可以方便的管理多個app。
可以在 processes.json定義應(yīng)用參數(shù):
{
"apps" : [{
"name" : "echo",
"script" : "examples/args.js",
"args" : "['--toto=heya coco', '-d', '1']",
"log_date_format" : "YYYY-MM-DD HH:mm Z",
"ignoreWatch" : ["[\\/\\\\]\\./", "node_modules"],
"watch" : true,
"node_args" : "--harmony",
"cwd" : "/this/is/a/path/to/start/script",
"env": {
"NODE_ENV": "production",
"AWESOME_SERVICE_API_TOKEN": "xxx"
}
},{
"name" : "api",
"script" : "./examples/child.js",
"instances" : "4",
"log_date_format" : "YYYY-MM-DD",
"log_file" : "./examples/child.log",
"error_file" : "./examples/child-err.log",
"out_file" : "./examples/child-out.log",
"pid_file" : "./examples/child.pid",
"exec_mode" : "cluster_mode",
"port" : 9005
},{
"name" : "auto-kill",
"script" : "./examples/killfast.js",
"min_uptime" : "100",
"exec_mode" : "fork_mode"
}]
}
然后運行:
$ pm2 start processes.json
$ pm2 stop processes.json
$ pm2 delete processes.json
$ pm2 restart processes.json
啟動過以后蔑穴,可以通過pm2 list查看app忠寻,并做相應(yīng)的處理
- name
app啟動名稱 - script
腳本文件位置 - cwd
腳本執(zhí)行的相對路徑
-args
腳本執(zhí)行參數(shù) - env
腳本執(zhí)行前設(shè)置的環(huán)境變量 - log_file
保存log文件路徑 - error_file
error log文件路徑 - out_file
out log文件路徑