Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Switch from fork to cluster mode in pm2

Tags:

node.js

pm2

I have a pm2 managed app that runs in fork mode. How can I switch it to cluster mode?

like image 947
Per Avatar asked Oct 29 '25 11:10

Per


1 Answers

You can take a look at this document.

Stop and delete your current app run on the pm2.

pm2 stop ${your app name}
pm2 delete ${your app name}

And rerun your app with arguments -i max:

pm2 start path/to/main.js -i max --name="${your app name}"
// Should use pm2 not pm

Or create a json config file and run your app with it

// processes.json
{
  "your-app-name" : [{
    "script"    : "path/to/main.js",
    "instances" : "max",
    "exec_mode" : "cluster"
  }]
}

pm2 start processes.json
like image 81
shuizhongyuemin Avatar answered Nov 01 '25 14:11

shuizhongyuemin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!