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?
PM2 will keep your application forever alive, auto-restarting across crashes and machine restarts.
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.
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:
pm2 startup
and follow the directions (you will have to perform a sudo
command; PM will tell you exactly what to do).pm2 start
, get your Node processes up and running just like you like them.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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With