process.argv behaves differently for pm2-runtime + cluster mode without pm2 daemon running
Open
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?
execute pm2-runtime start process.json without a running pm2 daemon, "start", "process.json" is included in application process.argv.
How could we reproduce this issue?
- create an
app.jswith contents below:
console.log(process.argv)
- create a
process.jsonwith:
{
"apps": [{
"name": "test-server",
"script": "app.js",
"instances": "1",
"exec_mode": "cluster"
}]
}
- make sure pm2 daemon not running and execute
pm2-runtime start process.json, it logs something like:
2021-01-01T17:29:41: PM2 log: Launching in no daemon mode
2021-01-01T17:29:41: PM2 log: App [test-server:0] starting in -cluster mode-
2021-01-01T17:29:41: PM2 log: App [test-server:0] online
[
'/usr/local/bin/node',
'/usr/local/lib/node_modules/pm2/lib/ProcessContainer.js',
'start',
'process.json'
]
- execute
pm2 ps && pm2-runtime start process.jsonand it logs something like:
[PM2] Spawning PM2 daemon with pm2_home=/root/.pm2
[PM2] PM2 Successfully daemonized
┌────┬────────────────────┬──────────┬──────┬───────────┬──────────┬──────────┐
│ id │ name │ mode │ ↺ │ status │ cpu │ memory │
└────┴────────────────────┴──────────┴──────┴───────────┴──────────┴──────────┘
[
'/usr/local/bin/node',
'/usr/local/lib/node_modules/pm2/lib/ProcessContainer.js'
]
pm2 ps is just for spawning the daemon process.
Supporting information
pm2, pm2-runtime + fork mode both works fine, it just the pm2-runtime.
--- PM2 report ----------------------------------------------------------------
Date : Fri Jan 01 2021 17:35:17 GMT+0800 (Central Standard Time)
===============================================================================
--- Daemon -------------------------------------------------
pm2d version : 4.5.0
node version : 14.15.1
node path : not found
argv : /usr/local/bin/node,/usr/local/lib/node_modules/pm2/lib/Daemon.js
argv0 : node
user : undefined
uid : 0
gid : 0
uptime : 0min
===============================================================================
--- CLI ----------------------------------------------------
local pm2 : 4.5.0
node version : 14.15.1
node path : not found
argv : /usr/local/bin/node,/usr/local/bin/pm2,report
argv0 : node
user : undefined
uid : 0
gid : 0
===============================================================================
--- System info --------------------------------------------
arch : x64
platform : linux
type : Linux
cpus : Intel(R) Core(TM) i5-8259U CPU @ 2.30GHz
cpus nb : 2
freemem : 1295839232
totalmem : 2612682752
home : /root
===============================================================================
--- PM2 list -----------------------------------------------
┌────┬────────────────────┬──────────┬──────┬───────────┬──────────┬──────────┐
│ id │ name │ mode │ ↺ │ status │ cpu │ memory │
└────┴────────────────────┴──────────┴──────┴───────────┴──────────┴──────────┘
===============================================================================
--- Daemon logs --------------------------------------------
/root/.pm2/pm2.log last 20 lines:
PM2 | 2021-01-01T17:32:39: PM2 log: App name:test-server id:0 disconnected
PM2 | 2021-01-01T17:32:39: PM2 log: App [test-server:0] exited with code [0] via signal [SIGINT]
PM2 | 2021-01-01T17:32:39: PM2 log: pid=837 msg=process killed
PM2 | 2021-01-01T17:32:40: PM2 log: PM2 successfully stopped
PM2 | 2021-01-01T17:35:17: PM2 log: ===============================================================================
PM2 | 2021-01-01T17:35:17: PM2 log: --- New PM2 Daemon started ----------------------------------------------------
PM2 | 2021-01-01T17:35:17: PM2 log: Time : Fri Jan 01 2021 17:35:17 GMT+0800 (Central Standard Time)
PM2 | 2021-01-01T17:35:17: PM2 log: PM2 version : 4.5.0
PM2 | 2021-01-01T17:35:17: PM2 log: Node.js version : 14.15.1
PM2 | 2021-01-01T17:35:17: PM2 log: Current arch : x64
PM2 | 2021-01-01T17:35:17: PM2 log: PM2 home : /root/.pm2
PM2 | 2021-01-01T17:35:17: PM2 log: PM2 PID file : /root/.pm2/pm2.pid
PM2 | 2021-01-01T17:35:17: PM2 log: RPC socket file : /root/.pm2/rpc.sock
PM2 | 2021-01-01T17:35:17: PM2 log: BUS socket file : /root/.pm2/pub.sock
PM2 | 2021-01-01T17:35:17: PM2 log: Application log path : /root/.pm2/logs
PM2 | 2021-01-01T17:35:17: PM2 log: Worker Interval : 30000
PM2 | 2021-01-01T17:35:17: PM2 log: Process dump file : /root/.pm2/dump.pm2
PM2 | 2021-01-01T17:35:17: PM2 log: Concurrent actions : 2
PM2 | 2021-01-01T17:35:17: PM2 log: SIGTERM timeout : 1600
PM2 | 2021-01-01T17:35:17: PM2 log: ===============================================================================
$ pm2 report
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with app.js, process.json, and pm2-runtime start process.json in cluster mode, both with and without a running daemon. Start by tracing the ProcessContainer.js launch path shown in the reported argv. Done means the application receives the same process.argv in both cases, without the extra start and process.json arguments.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100