Skip to content
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

script to spawn pm2 hangs #235

Closed
caiguanhao opened this issue Dec 26, 2013 · 3 comments
Closed

script to spawn pm2 hangs #235

caiguanhao opened this issue Dec 26, 2013 · 3 comments

Comments

@caiguanhao
Copy link

If your pm2 is not runnig and you try to spawn pm2 from a script, it hangs. Abort the script and then run it again, it becomes normal.

pkill node         // kill pm2 process, in linux use: kill `pgrep pm2`
node app.js        // do not exit
                   // ctrl-c to abort
node app.js        // normal

app.js:

var spawn = require('child_process').spawn;
var pm2 = spawn('pm2', [ 'jlist' ]);
pm2.stdout.on('data', function(data) {
  process.stdout.write(data.toString());
});
pm2.stderr.on('data', function(data) {
  process.stderr.write(data.toString());
});
pm2.on('close', function(code) {
  console.log('exit code: ' + code);
});

please add support for pm2 to run from other script (for example, the Gruntfile.js).

node version: v0.10.24
pm2 version: v0.6.12
tested on mac & linux

@Unitech
Copy link
Owner

Unitech commented Jan 10, 2014

Yep, pm2 should be already daemonized before launching commands.

A ping method will be available on the 0.6.16, you should call it and wait for his answer before doing any operations with pm2. Is this approach okey for you ?

@caiguanhao
Copy link
Author

If pm2 hasn't started yet, running the following code will not hang, but need to kill the process manually at the end of the code. I think pm2 --version would work just like pm2 ping in this example. This can be a temporary fix. Or pm2 should start with system login.

var spawn = require('child_process').spawn;
var ping = spawn('pm2', [ 'ping' ]);
ping.stdout.on('data', function(data) {
  var pm2 = spawn('pm2', [ 'jlist' ]);
  pm2.stdout.on('data', function(data) {
    process.stdout.write(data.toString());
  });
  pm2.stderr.on('data', function(data) {
    process.stderr.write(data.toString());
  });
  pm2.on('close', function(code) {
    console.log('exit code: ' + code);
    process.kill(ping);
  });
});

@tjwebb
Copy link

tjwebb commented Apr 14, 2014

What is the command that needs to run prior to pm2 start ...? I am also having this issue.

EDIT: Running pm2 ping first seems to do the trick. It'd be great to have less insidious way of failing, though, than an error-less hang.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants