Skip to content

PM2 executed from within node inherits command line arguments #941

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
stevekeiser opened this issue Jan 15, 2015 · 7 comments
Closed

PM2 executed from within node inherits command line arguments #941

stevekeiser opened this issue Jan 15, 2015 · 7 comments
Labels

Comments

@stevekeiser
Copy link

This is a weird one. Hopefully I can explain clearly. Let's say that I run pm2 start a.js -- 3000 and a.js calls require('child_process').exec('pm2 start b.js -- 4000') then b.js will receive 3000 as it's argument instead of 4000, as expected. This is true even if a.js uses the API, e.g. pm2.start('b.js', {rawArgs: ['--', 4000]}). The child process seems to inherit the command line arguments of the parent.

@Tjatse Tjatse added the T: Bug label Jan 17, 2015
@catchdave
Copy link

I'm having the same problem too. When the parent process is run with command line args, the child processes started via pm2.start() has the arguments (that were specified via pm2.start) ignored and uses the parents arguments instead.

Example:
pm2 start processes.json

processes.json:

{ apps: [
    { name: "loader.js", args: ["--debug", "--path=/var/foo"] }
]}

loader.js

var curProcess = 'foo'; // this comes from somewhere else
var params = {
    name: curProcess,
    rawArgs: ['--', "--bar"]
};
pm2.start('sub-process.js', params);

In the above example, pm2 will start the sub process as pm2 start sub-process.js --debug,--path=/var/foo instead of the expected pm2 start sub-process.js --bar.

Note, I have to use rawArgs here to workaround another pm2 bug specified here: #590


It may be worth noting that when this bug occurs, pm2 show X also breaks for the subprocesses with the below error:

Describing process with pid 248 - name ping
undefined:1
--debug,--log-dir=/var/log
 ^
SyntaxError: Unexpected number
at Object.parse (native)
at Object.UX.describeTable (/usr/local/lib/node_modules/pm2/lib/CliUx.js:68:71)
at /usr/local/lib/node_modules/pm2/lib/CLI.js:1140:12
at Array.forEach (native)
at /usr/local/lib/node_modules/pm2/lib/CLI.js:1139:18
at /usr/local/lib/node_modules/pm2/node_modules/pm2-axon-rpc/lib/client.js:45:10
at Parser.<anonymous> (/usr/local/lib/node_modules/pm2/node_modules/pm2-axon/lib/sockets/req.js:67:8)
at Parser.EventEmitter.emit (events.js:95:17)
at Parser._write (/usr/local/lib/node_modules/pm2/node_modules/pm2-axon/node_modules/amp/lib/stream.js:91:16)
at doWrite (_stream_writable.js:226:10)

@catchdave
Copy link

@Unitech : Any ideas about this bug?

@Tjatse
Copy link
Collaborator

Tjatse commented Feb 11, 2015

I've confirmed this bug. Just need time to fix it.

@michAtEl
Copy link

michAtEl commented Apr 6, 2015

I've the same problem. It happens only, if the process, that calls pm2.start() is running in pm2. If I start the process, that calls pm2.start(), without pm2, everything works fine.

@mathieumante
Copy link

+1
I've the same problem, and also with restart.
Do you have any ideas about this bug?

@jshkurti
Copy link
Contributor

Can you try npm i -g git://github.com/Unitech/PM2#development ?
I think this might have been fixed by https://github.com/Unitech/PM2/pull/1282/files#diff-96936c803a7f9ae2c51530cc944a8cceR324

@Unitech
Copy link
Owner

Unitech commented Nov 23, 2016

Issue fixed since PM2 1.1.3

$ npm install pm2@latest -g
$ pm2 update

@Unitech Unitech closed this as completed Nov 23, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants