官方文檔:http://pm2.keymetrics.io/docs/usage/application-declaration/#special-ext-type
一蝌数、基本命令
pm2 start app.js //直接啟動(dòng)js文件
pm2 start start.json //啟動(dòng)自定義的json配置文件
pm2 start start.json --env production //啟動(dòng)json,并指定使用配置文件中的production,見(jiàn) 第二節(jié)
二扔亥、json配置文件
eg: start.json
{
"name" : "app_name", // 應(yīng)用名稱
"script" : "./app.js", // 實(shí)際啟動(dòng)腳本
"cwd" : "./", // 指定工作路徑,即入口文件路徑
"error_file" : "./logs/app-err.log", // 錯(cuò)誤日志路徑
"out_file" : "./logs/app-out.log", // 普通日志路徑
"env": {
"NODE_ENV": "local" // 默認(rèn)環(huán)境參數(shù)笆豁,當(dāng)前指定為本地環(huán)境
},
"env_test": {
"NODE_ENV": "test" // 指定測(cè)試環(huán)境使用
},
"env_production": {
"NODE_ENV": "production" //指定為正式環(huán)境使用
}震嫉,
"watch" : true, //boolean or []監(jiān)聽(tīng)文件變化,重啟
"ignore_watch" : [] //list of regex to ignore some file or folder names by the watch feature
"min_uptime" : 10000 //被認(rèn)為啟動(dòng)成功的最小運(yùn)行時(shí)間刹帕,number(ms)or string (10s吵血,5m,1h)
"max_restarts" : 10 //運(yùn)行時(shí)間少于min_uptime時(shí)偷溺,最大重啟次數(shù)蹋辅,即短時(shí)間內(nèi)最大重啟次數(shù)
"max_memory_restart" : "300M"
}
使用:
pm2 start start.json 默認(rèn)啟動(dòng)方式
pm2 start start.json --env test 指定使用env_test配置的環(huán)境變量
pm2 start start.json --env production 指定使用env_production配置的環(huán)境變量