简体   繁体   中英

Node PM2 json configuration to split cluster and fork mode based on environment

In a PM2 JSON configuration, is there a way to choose cluster vs. fork mode based on the environment?

Also, it seems like putting watch inside the development environment doesn't actualy restart on changes, even though pm2 status shows watch is enabled?

I've tried this configuration but don't get the expected results:

    "env_production": {
        "NODE_ENV": "production",
        "watch": false,
        "exec_mode": "cluster",
        "instances": "max"
    },
    "env": {
        "watch": ["files/to/watch/*"],
        "ignore_watch" : ["files/to/watch/not/*"],
        "exec_mode": "fork"
    },

When I run pm2 start app.json it results in mode = cluster but I expect mode = fork

When I kill and re-run pm2 start app.json --env production it results in mode = cluster as expected but the number of workers does not equal number of cores.

我通过在JSON配置文件中将每个环境拆分成自己的“应用程序”来解决此问题。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM