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

Wrong exit code on success #470

Closed
dcharbonnier opened this issue May 16, 2014 · 10 comments
Closed

Wrong exit code on success #470

dcharbonnier opened this issue May 16, 2014 · 10 comments

Comments

@dcharbonnier
Copy link

# pm2 delete all && echo "OK" || echo "NOK"
PM2 Stopping and deleting all processes
No processes launched
NOK

Just to anticipate a possible troll

git checkout develop && echo "OK" || echo "NOK"
Already on 'develop'
Your branch is up-to-date with 'origin/develop'.
OK
@cryptoDevTrader
Copy link

I'm seeing the same issue. We use Rundeck (http://rundeck.org/) for automated deployments and the incorrect exit code causes remote scripts to hang.

@cryptoDevTrader
Copy link

It looks like this may duplicate issue #235.

@soyuka
Copy link
Collaborator

soyuka commented May 22, 2014

Your process isn't launched so pm2 failed deleting it. Normal behavior...

@divThis in the https://github.com/Unitech/pm2/blob/master/lib/CLI.js file you can notice that there is a cst.SUCCESS_EXIT = 0 code that is returning when exiting.

I'll take a look at rundeck though, interesting.

A solution might be to check if the process is alive before executing the delete command.

@soyuka soyuka closed this as completed May 22, 2014
@dcharbonnier
Copy link
Author

this is not the issue, the process IS launched.

pm2 ping; pm2 delete all && echo "OK" || echo "NOK"
{ msg: 'pong' }
PM2 Stopping and deleting all processes
No processes launched
NOK

you launch a command, you get the expected result and the command tell you there was an error

@dcharbonnier
Copy link
Author

@divThis you can do that ...

#!/bin/sh
RES=pm2 delete all 2>&1 >/dev/null;
EXIT_CODE=$?;
if [ $EXIT_CODE -ne 0 ];then
if [ "x$RES" = "xNo processes launched" ]; then
EXIT_CODE=0;
fi;
fi;
exit $EXIT_CODE;

@soyuka
Copy link
Collaborator

soyuka commented May 22, 2014

❯ pm2 ping; pm2 delete all && echo "OK" || echo "NOK"                                                        ⚑ ◒  6d
{ msg: 'pong' }
PM2 Stopping and deleting all processes
┌──────────┬────┬──────┬─────┬────────┬───────────┬────────┬────────┬──────────┐
│ App name │ id │ mode │ PID │ status │ restarted │ uptime │ memory │ watching │
└──────────┴────┴──────┴─────┴────────┴───────────┴────────┴────────┴──────────┘
 Use `pm2 desc[ribe] <id>` to get more details
OK

@dcharbonnier
Copy link
Author

... and if you launch this command twice you will get OK and then NOK ;-)

@soyuka
Copy link
Collaborator

soyuka commented May 22, 2014

Yes then the process is deleted, it no longer exists

@dcharbonnier
Copy link
Author

No, ping start the pm2 process... can you just do this and paste result ?

pm2 ping; pm2 delete all && echo "OK" || echo "NOK" 
pm2 ping; pm2 delete all && echo "OK" || echo "NOK" 

@soyuka
Copy link
Collaborator

soyuka commented May 22, 2014

pm2 ping doesn't start anything, it just give a pong message if pm2 is started, (if not it launches it). It does not start or check instances.

pm2 delete all on the other hand is removing all processes from the pm2 list so if you'd want to start one again you'd have to use pm2 start index.js

Maybe that you're looking for pm2 dump and pm2 resurrect commands.

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