node.jsubuntunginxpm2

Pm2 process stops running automatically in ubuntu server


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 days without any error. When I check on the server I see that my pm2 list is empty.

The code I use to start my app:

cd myapp
pm2 start npm --name='backend' -- start

It somehow looks as if pm2 is reset after a while. But I'm trying to keep running it forever, but then I run into the same problem. Is there some way to prevent the pm2 list from getting empty?

I run the same cmd to start it and again its happening.I want to keep running the pm2 process in my server without stopping automatically.


Solution

  • Consider checking the uptime of your server to see if it restarted for some reason and interrupted the pm2 process.

    If this is the case, you can run pm2 startup and it will take a snapshot of your current processes and start them automatically when the server starts.

    If you update the pm2 process, add another one, etc., run pm2 save to update the startup process list.

    When running pm2 startup without sudo privileges, you will need to paste a command to update an environment variable, read more on this here.