Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pm2 process stops running

I have a node chat application that needs to keep running on my server (ubuntu with nginx). The problem is that the application stops after a few hours or days. When I check on the server I see that my pm2 list is empty.

The code I use to start my app:

pm2 start notification_server/index.js

It somehow looks as if pm2 is reset after a while. I also tried using forever, but then I run into the same problem. Is there some way to prevent the pm2 list from getting empty?

like image 843
Johan Avatar asked Oct 06 '15 17:10

Johan


People also ask

Does pm2 auto restart?

PM2 will keep your application forever alive, auto-restarting across crashes and machine restarts.


2 Answers

Did you try checking logs $ pm2 logs for you application?

Most likely it will tell you why your application was terminated or maybe it just exited as it supposed to. You could find something like that there:

PM2 | App [app] with id [0] and pid [11982], exited with code [1] via signal [SIGINT]

This can tell you what happened. Without more details, it's hard to give you a better answer.

like image 134
jkulak Avatar answered Sep 28 '22 11:09

jkulak


This is most likely an indication that your server is rebooting. When your server reboots, PM2 shuts down and deletes all Node instances from its "status" list.

You can perform the following steps to make PM2 relaunch your Node programs start back up on reboot:

  1. Run pm2 startup and follow the directions (you will have to perform a sudo command; PM will tell you exactly what to do).
  2. Through pm2 start, get your Node processes up and running just like you like them.
  3. Run pm2 save to register the current state of things as what you want to see on system startup.

Source: http://pm2.keymetrics.io/docs/usage/startup/

like image 34
D. Levine Avatar answered Sep 28 '22 11:09

D. Levine