About pm2 ecosystem file generator
PM2 keeps Node.js apps running, restarts them on failure and can run several instances in cluster mode. An ecosystem file stores the settings.
Useful settings
- instances and exec_mode: 'cluster' to use all CPU cores.
- env and env_production for environment variables.
- max_memory_restart to restart a leaking process.
Starting on boot
Run pm2 startup and pm2 save so your processes return after a server restart.
A worked example
An ecosystem file with the app name web, script server.js, instances set to max, exec_mode cluster and env_production with NODE_ENV=production lets you run pm2 start ecosystem.config.js --env production. PM2 then runs one process per CPU core and restarts any that crash.
Useful commands
- pm2 logs and pm2 monit show output and resource use.
- pm2 reload web restarts without downtime in cluster mode.
- pm2 save and pm2 startup bring processes back after reboots.
