Pm2 process stops running
Asked Answered
P

2

9

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?

Petronia answered 6/10, 2015 at 17:56 Comment(1)
this is possible when your system reboots/restart. you can check last start time of your system and check what happened. and also check logs with pm2 logs to know more about the errors.Pearlpearla
C
10

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/

Caylacaylor answered 10/2, 2018 at 22:0 Comment(0)
S
6

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.

Sometime answered 25/10, 2016 at 1:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.