PM2

PM2 Exponential Backoff Restart Delay

Exponential Backoff Restart Delay Available in PM2 >= 3.2 A new restart mode has been implemented on PM2 Runtime, making your application restarts in a smarter way. Instead of restarting your application like crazy when exceptions happens (e.g. database is down), the exponential backoff restart will increase incrementaly the time between restarts, reducing the pressure on your DB or your external provider… Pretty easy to use: CLI: $ pm2 start app.js --exp-backoff-restart-delay=100 Or via ecosystem.config.js file: module.exports = [{ script: 'app.js', exp_backoff_restart_delay: 100 }] When an application...

Read more...

PM2 Logs

Log management PM2 allows you to easily manage your application’s logs. You can display the logs coming from all your applications in real-time, flush them, and reload them. There are also different ways to configure how PM2 will handle your logs (separated in different files, merged, with timestamp…) without modifying anything in your code. Application log options CLI When running pm2 start app.js [OPTIONS] you can pass any of this options to the CLI: -l --log [path] ...

Read more...

PM2 When starting a new process

When starting a new process PM2 will inject environment in this order when starting a new process : First the PM2 CLI will use its environment so the current environment of your shell will be injected.PM2 will then inject the environment that you can configure with the ecosystem file : module.exports = { apps : [ { name: "myapp", script: "./app.js", ...

Read more...

PM2 Graceful Stop

Graceful Stop To allow graceful restart/reload/stop processes, make sure you intercept the SIGINT signal and clear everything needed (like database connections, processing jobs…) before letting your application exit. process.on('SIGINT', function() { db.stop(function(err) { process.exit(err ? 1 : 0); }); }); Now pm2 reload will become a gracefulReload. Configure the kill timeout Via CLI, this will lengthen the timeout to 3000ms: pm2 start app.js --kill-timeout 3000 Via Ecosystem File: module.exports = { apps : [{ name: "app", script: "./app.js", ...

Read more...

PM2 Ecosystem File

Ecosystem File PM2 empowers your process management workflow. It allows you to fine-tune the behavior, options, environment variables, logs files of each application via a process file. It’s particularly useful for micro-service based applications. Configuration format supported are Javascript, JSON and YAML. Generate configuration To generate a sample process file you can type this command: pm2 ecosystem This will generate a sample ecosystem.config.js: module.exports = { apps : [{ name: "app", script: "./app.js", env: { ...

Read more...