The Be Sure Blog

Code Snippets | Problem Solving | Tips & Tricks

The Be Sure Blog banner

Disabling the auto restart of PM2 processes

posted on 4.6.2023 by Below Surface in "PM2"

PM2 is a great tool for running Node.js applications on a web server. In my case it's an Ubuntu server with Nginx installed as a reverse proxy. I run four websites and one API endpoint from this instance, mostly without any issues.

Sometimes though the build of a Next.js application would fail, but the PM2 process would still start. This resulted in endless process restarts and led to exhausting all the server resources. All websites on this server would be unavailable due to the lack of resources.

I figured, that restarting this processes would not do anything to fix the problem, so I decided to disable this PM2 feature, by appending the option

--no-autorestart

to the PM2 start command.

In my case, the auto restart option was never used, because the processes did never crash in the first place, even after weeks of being online. Still I will have an eye on this topic, since the goal is to have the highest percentage of uptime for all websites as possible.


If you need, those are my PM2 commands:

Node.js Backend Server:

pm2 start server.js --name mywebsite.com-backend --no-autorestart

Next.js Frontend Server:

pm2 start npm --name mywebsite.com-frontend --no-autorestart -- start 

Tags:

pm2
node process manager

Sources:

https://pm2.keymetrics.io/docs/usage/quick-start/

More posts of this category

Useful PM2 commands for Linux

PM2 is a well working process manager for the Node.js runtime

PM2

Troubleshoot why a PM2 process errors

Some helpful commands and logs to look at to identify the issue

PM2