Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

222
Views
How to prevent PM2 autorestart after the app is unresponsive for some period of time?

My Node.Js Docker app runs on pm2 and uses the following config:

module.exports = [
  {
    script: 'dist/src/main.js',
    name: 'infrasonic',
    exec_mode: 'fork_mode',
    autorestart: true,
    env: {
      NODE_ENV: 'production',
    },
    env_development: {
      NODE_ENV: 'development',
    },
    watch: process.env.NODE_ENV == 'development' ? true : false,
    watch_delay: 60000,
    ignore_watch: ['node_modules'],
    max_memory_restart: '1G',
  },
];

in this setup if my app is unresponsive for about a minute, PM2 restarts the app.

I don't want this behavior, so I want it to wait at least 2 minutes of unresponsiveness before it restarts the app.

I rewrote the ecosystem.config.js file in the following way:

module.exports = [
  {
    script: 'dist/src/main.js',
    name: 'infrasonic',
    exec_mode: 'cluster',
    instances: 1,
    autorestart: true,
    env: {
      NODE_ENV: 'production',
    },
    env_development: {
      NODE_ENV: 'development',
    },
    watch: process.env.NODE_ENV == 'development' ? true : false,
    watch_delay: 60000,
    ignore_watch: ['node_modules'],
    max_memory_restart: '1G',
  },
];

switching it into cluster mode as I read it has 0 downtime.

Do you think there's another solution where I can specify the duration of unresponsiveness (120 seconds) directly after which PM2 restarts?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!