Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does pm2 auto restart application after reboot by default?

Tags:

I have an issue with my linux server and need to reboot, before that I run my node application with pm2 start server.js without any other config. Can it auto restart my app after reboot server?

like image 931
Andy Avatar asked Feb 06 '20 12:02

Andy


People also ask

Does pm2 auto restart after reboot?

The start script sets up PM2 as a service under the init system. When the server restarts, it will automatically restart PM2, which will then restart all the Node. js applications/processes it is managing. In this article, we will show you how to deploy PM2 as a service to reliably manage your Node.

What does pm2 reload do?

With reload, pm2 restarts all processes one by one, always keeping at least one process running. It also states that: If the reload system hasn't managed to reload your application, a timeout will fallback to a classic restart.


1 Answers

Not by default, but PM2 can do so using a startup script:

PM2 can generate startup scripts and configure them in order to keep your process list intact across expected or unexpected machine restarts.

After generating your startup script (read also this comment), take a look at pm2 save:

Once you started all the applications you want to manage, you have to save the list you wanna respawn at machine reboot with:

pm2 save

like image 128
pzaenger Avatar answered Sep 18 '22 13:09

pzaenger