Unitech / Unitech/pm2

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

Open
#5,543 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
43.3k
Forks
2.7k
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Read lib/API.js around line 1012 and trace pm2-runtime argument handling when loading .ecosystem.config.js. Reproduce the Docker command with --instances 2, compare it with the resulting process count, and locate an existing test entry point for this path if available. Done means the CLI value controls the configured app's instance count.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
cli, devops
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.