Show pm2 command that started a process
Asked Answered
E

1

27

From my linux machine, typing pm2 status shows me

│ App name     │ id │ mode │ pid   │ status  │ restart │ uptime │ memory      │ watching │
├──────────────┼────┼──────┼───────┼─────────┼─────────┼────────┼─────────────┼──────────┤
│ gamatrix-dev │ 0  │ fork │ 0     │ stopped │ 0       │ 0      │ 0 B         │ disabled │
│ gamatrix     │ 1  │ fork │ 22779 │ online  │ 10      │ 2D     │ 78.793 MB   │ disabled │
│ elevacad     │ 2  │ fork │ 14106 │ online  │ 13      │ 3D     │ 36.227 MB   │ disabled │

I'm pretty sure for the last two lines, they were initiated by a command like pm2 start someapp.js. Is there a way to know what value someapp.js really was that started the process?

Europium answered 3/10, 2015 at 15:30 Comment(1)
G
25

As mentioned in a comment, use

pm2 describe

That will produce copious output similar to the following:

┌───────────────────┬─────────────────────────────────────────────────────────────────────────────────────┐
│ status            │ online                                                                              │
│ name              │ random                                                                              │
│ namespace         │ default                                                                             │
│ version           │ 1.0.0                                                                               │
│ restarts          │ 0                                                                                   │
│ uptime            │ 107m                                                                                │
│ script path       │ /home/pi/checkout/random-monitor.ts                                                 │
│ script args       │ N/A                                                                                 │
│ error log path    │ /home/pi/.pm2/logs/random-error.log                                                 │
│ out log path      │ /home/pi/.pm2/logs/random-out.log                                                   │
│ pid path          │ /home/pi/.pm2/pids/random-1.pid                                                     │
│ interpreter       │ /home/pi/.nvm/versions/node/v12.19.0/lib/node_modules/pm2/node_modules/.bin/ts-node │
│ interpreter args  │ N/A                                                                                 │
│ script id         │ 1                                                                                   │
│ exec cwd          │ /home/pi/checkout                                                                   │
│ exec mode         │ fork_mode                                                                           │
│ node.js version   │ 12.19.0                                                                             │
│ node env          │ N/A                                                                                 │
│ watch & reload    │ ✘                                                                                   │
│ unstable restarts │ 0                                                                                   │
│ created at        │ 2020-11-18T00:17:04.623Z                                                            │
└───────────────────┴─────────────────────────────────────────────────────────────────────────────────────┘

The interpreter, interpreter args, script path and script args should give you what you are after. See also this answer to a similar question.

Note: For the sake of completeness, the actual command requires a name or argument for which process you'd like information about. In the case above the full command is pm2 describe random where random above is the name of the process as you can tell from the output. You may run pm2 status to get a list of processes along with their id and name.

Note: I left the command above listed as just pm2 describe without the argument to avoid potentially confusing error messages for cut and paste users. I think the error message pm2 describe produces indicating a missing required argument is far less confusing than one stating that "random" is not found or even worse if I listed the argument as name|id which would cause the output to be piped to the program id that may or may not exist depending on the platform on which you are running.

Goggleeyed answered 11/1, 2022 at 2:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.