Unitech / pm2

Node.js Production Process Manager with a built-in Load Balancer.
https://pm2.keymetrics.io/docs/usage/quick-start/
Other
41.57k stars 2.62k forks source link

PM2 (pm2-runtime) does not read cli --instances param if run ecosystem file (only docker) #5543

Open VeXell opened 1 year ago

VeXell commented 1 year ago

What's going wrong?

I am using docker container and to run PM2 with different count of instances depends on environment (prod or staging). In both cases i have common ecosystem config:

module.exports = {
    apps: [
        {
            name: 'app',
            script: 'build/app.js',
            autorestart: true,
            watch: false,
            max_memory_restart: '512M',
            vizion: false,
            exec_mode: 'cluster',
        },
    ],
};

And command in docker

CMD ["pm2-runtime", "--instances", "2", "--json", ".ecosystem.config.js"]

When i run docker container PM2 spawns only 1 instance instead of 2. I think it might be a problem in that file https://github.com/Unitech/pm2/blob/5e708459aca32903fd363230e24c37b3e38bb48d/lib/API.js#L1012

Because in that case instances has String type

Supporting information

--- Daemon logs --------------------------------------------
/home/nodejs/.pm2/pm2.log last 20 lines:
PM2        | 2023-01-30T13:23:21: PM2 log: ===============================================================================
PM2        | 2023-01-30T13:23:21: PM2 log: --- New PM2 Daemon started ----------------------------------------------------
PM2        | 2023-01-30T13:23:21: PM2 log: Time                 : Mon Jan 30 2023 13:23:21 GMT+0000 (Coordinated Universal Time)
PM2        | 2023-01-30T13:23:21: PM2 log: PM2 version          : 5.2.2
PM2        | 2023-01-30T13:23:21: PM2 log: Node.js version      : 14.21.2
PM2        | 2023-01-30T13:23:21: PM2 log: Current arch         : x64
PM2        | 2023-01-30T13:23:21: PM2 log: PM2 home             : /home/nodejs/.pm2
PM2        | 2023-01-30T13:23:21: PM2 log: PM2 PID file         : /home/nodejs/.pm2/pm2.pid
PM2        | 2023-01-30T13:23:21: PM2 log: RPC socket file      : /home/nodejs/.pm2/rpc.sock
PM2        | 2023-01-30T13:23:21: PM2 log: BUS socket file      : /home/nodejs/.pm2/pub.sock
PM2        | 2023-01-30T13:23:21: PM2 log: Application log path : /home/nodejs/.pm2/logs
PM2        | 2023-01-30T13:23:21: PM2 log: Worker Interval      : 30000
PM2        | 2023-01-30T13:23:21: PM2 log: Process dump file    : /home/nodejs/.pm2/dump.pm2
PM2        | 2023-01-30T13:23:21: PM2 log: Concurrent actions   : 2
PM2        | 2023-01-30T13:23:21: PM2 log: SIGTERM timeout      : 1600
PM2        | 2023-01-30T13:23:21: PM2 log: ===============================================================================
PM2        | 2023-01-30T13:23:32: PM2 log: App [pm2-autoscale:0] starting in -fork mode-
PM2        | 2023-01-30T13:23:32: PM2 log: App [pm2-autoscale:0] online
inspiraller commented 3 months ago

Maybe try adding this to config: [... instances: 2 ]

VeXell commented 3 months ago

@inspiraller I have dynamic cases when i have instances:4 in the config (and inside docker container) and when i deploy it to the staging, i want to run pm2 with the same config but less instances (because staging has less resources). My patch (pull request) solve this problem. This is issue inside pm2.