Cluster mode using pm2

Hi,

I am trying to run strapi with pm2 cluster mode but it only runs properly 1 process, the other/s just keep restarting with this message:

error: The port 1337 is already used by another application.

1|app | > strapi-test@0.1.0 start 1|app | > strapi start PM2 | App name:app id:1 disconnected PM2 | App [app:1] exited with code [1] via signal [SIGINT] PM2 | App [app:1] starting in -cluster mode- PM2 | App [app:1] online

But I don’t how to make it to use other ports… Any hints? Thanks!

This topic has been created from a Discord post (1220629560002084935) to give it more visibility.
It will be on Read-Only mode here.
Join the conversation on Discord

have you been able to solve it?

I’ve done this for my redcron plugin redcron | Strapi Market in the readme has instructions, you need to make a new file and tell pm 2 to run that.

`pm2 start --name=“mystrapiapp” server.js -i 2

`

yes, finally I solved it using the increment_var property from pm2. My ecosystem.config.js now looks like:

module.exports = {
apps: [{
name: ‘strapi’,
script: ‘npm’,
args: ‘start’,
exec_mode: ‘cluster’,
instances: ‘max’,
increment_var: ‘PORT’,
merge_logs: true,
env_staging: {
PORT: 1337,
NODE_ENV: “staging”
},
env_production: {
PORT: 1337,
NODE_ENV: “production”
}
}]
}

Worth noting that I had to set the port so the increment_var works. Another issue I’ve found is that if you use pm2 restart or reload, the cluster fails again. You have to stop, delete and start again. But this is more a pm2 issue I guess…