Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pm2 graceful restart to improve user experience and avoid problems

Tags:

node.js

pm2

Is there a way to do a graceful restart of pm2 for all nodejs processes? I'm looking for something similar to Apache's graceful restart. Want to avoid killing a server execution in progress for every code deployment.

like image 407
steampowered Avatar asked Oct 14 '15 00:10

steampowered


1 Answers

pm2 restart kills and restarts the process.

If you have clusters enabled, you can essentially do hot reload with 0s downtime. pm2 reload should be enough for most cases.

However, what you exactly want is: pm2 gracefulReload which does exactly what Apache's graceful restart does. That is, it will close all existing connections before restarting.

You can find more info here: http://pm2.keymetrics.io/docs/usage/cluster-mode/#graceful-reload

like image 77
Rahat Mahbub Avatar answered Oct 10 '22 01:10

Rahat Mahbub