JSON 文件中所有进程的 PM2 通用设置
PM2 Common Settings For All Processes in JSON File
我目前正在使用 pm2
启动多个 Node.js 进程。这些进程定义在 JSON 文件中,运行
使用该文件
pm2 start pm2.json
从下面的JSON文件可以看出,有很多重复。例如,更改 error_file
位置或将变量 time
设置为 true
涉及大量重复,如果在 JSON 文件.
是否可以通过在文件中仅设置一次 time
变量并将其应用于所有进程来简化 JSON 文件?
另外,是否可以使用模板来定义error_file
和out_file
,比如"../logs/${name}-error.log"
?
例子pm2.json
{
"apps": [
{
"name": "foo-a",
"script": "./foo/a.js",
"args": "-e apple",
"error_file": "../logs/foo-a-error.log",
"out_file": "../logs/foo-a-out.log",
"time": true
},
{
"name": "foo-b",
"script": "./foo/b.js",
"args": "-e banana",
"error_file": "../logs/foo-b-error.log",
"out_file": "../logs/foo-b-out.log",
"time": true
}, {
"name": "bar-c",
"script": "./bar/c.js",
"args": "-e cranberry",
"error_file": "../logs/bar-c-error.log",
"out_file": "../logs/bar-c-out.log",
"time": true
},
...
您可以使用 js
文件代替 json
文件,它将允许您为 repetition part
.
创建和使用通用 variable/function
const time = true
module.exports = {
"apps": [
{
"name": "foo-a",
"script": "./foo/a.js",
"args": "-e apple",
"error_file": "../logs/foo-a-error.log",
"out_file": "../logs/foo-a-out.log",
"time": time
},
{
"name": "foo-b",
"script": "./foo/b.js",
"args": "-e banana",
"error_file": "../logs/foo-a-error.log",
"out_file": "../logs/foo-a-out.log",
"time": time
}, {
"name": "bar-c",
"script": "./bar/c.js",
"args": "-e cranberry",
"error_file": "../logs/bar-c-error.log",
"out_file": "../logs/bar-c-out.log",
"time": time
},
...
我目前正在使用 pm2
启动多个 Node.js 进程。这些进程定义在 JSON 文件中,运行
pm2 start pm2.json
从下面的JSON文件可以看出,有很多重复。例如,更改 error_file
位置或将变量 time
设置为 true
涉及大量重复,如果在 JSON 文件.
是否可以通过在文件中仅设置一次 time
变量并将其应用于所有进程来简化 JSON 文件?
另外,是否可以使用模板来定义error_file
和out_file
,比如"../logs/${name}-error.log"
?
例子pm2.json
{
"apps": [
{
"name": "foo-a",
"script": "./foo/a.js",
"args": "-e apple",
"error_file": "../logs/foo-a-error.log",
"out_file": "../logs/foo-a-out.log",
"time": true
},
{
"name": "foo-b",
"script": "./foo/b.js",
"args": "-e banana",
"error_file": "../logs/foo-b-error.log",
"out_file": "../logs/foo-b-out.log",
"time": true
}, {
"name": "bar-c",
"script": "./bar/c.js",
"args": "-e cranberry",
"error_file": "../logs/bar-c-error.log",
"out_file": "../logs/bar-c-out.log",
"time": true
},
...
您可以使用 js
文件代替 json
文件,它将允许您为 repetition part
.
const time = true
module.exports = {
"apps": [
{
"name": "foo-a",
"script": "./foo/a.js",
"args": "-e apple",
"error_file": "../logs/foo-a-error.log",
"out_file": "../logs/foo-a-out.log",
"time": time
},
{
"name": "foo-b",
"script": "./foo/b.js",
"args": "-e banana",
"error_file": "../logs/foo-a-error.log",
"out_file": "../logs/foo-a-out.log",
"time": time
}, {
"name": "bar-c",
"script": "./bar/c.js",
"args": "-e cranberry",
"error_file": "../logs/bar-c-error.log",
"out_file": "../logs/bar-c-out.log",
"time": time
},
...