Search code examples
node.jsnpmpm2forever

Get status of forever app or pm2 app


I am currently using forever but am considering switching to pm2 because forever does not provide a status option.

I cannot do:

forever status myApp

To determine if my app is running or not I must do:

forever list | grep -i myApp

And even with this it is unreliable because myApp might be listed in a stopped state (I appreciate you could come up with some ugly grep solution to accomodate but I want something natural).

With pm2 the docs say you can do:

pm2 show myApp # Show all informations about application

pm2 seems far more natural.

Any thoughts on how to get app status using forever without grepping the forever list?

How does pm2 compare regarding getting app status?


Solution

  • Forever cannot do this without using forever list.

    pm2 can and pm2 show works great with expected exit codes.

    I tried pm2 for this sole reason and found it much better than Forever. It does everything Forever does but (unbelievable but true) even simpler than Forever.

    The commands are the same with more.

    Example:

    forever start app.js
    
    pm2 start app.js --name "api" // built in pidfile management here
    
    pm2 start app.js -i 0 --name "api" // load balance your app on all cores! WOW!
    
    pm2 list // same as forever list
    
    pm2 show api // returns 0 or 1 return code as expected
    
    pm2 restart api // if running on multiple cores, restarts all associated processes
    

    Forever is dead, pm2 is the new king! PM2 forever!

    No need for reboot crontab entries. pm2 handles that with:

    pm2 startup
    
    pm2 save
    

    Done!