Unitech / pm2

Node.js Production Process Manager with a built-in Load Balancer.
https://pm2.keymetrics.io/docs/usage/quick-start/
Other
41.34k stars 2.61k forks source link

PM2 messing up watch with ignore flags #5057

Open AltayAkkus opened 3 years ago

AltayAkkus commented 3 years ago

What's going wrong?

I updated my ecosystem.config.js to ignore changes in a upload folder, because that bricks my application. Now the ecosystem file bricks my application :sunglasses:

How could we reproduce this issue?

Run Strapi, add this ecosystem.config.json and start it via pm2 start

module.exports = {
  apps: [
    {
      name: 'strapi',
      cwd: '/home/altay/redacted',
      script: 'npm',
      args: 'start',
      watch: true,
      ignore_watch: ['node_modules','public/uploads'],
      env: {
        NODE_ENV: 'production',
        DATABASE_HOST: 'localhost', // database endpoint
        DATABASE_PORT: '5432',
        DATABASE_NAME: 'strapi', // DB name
        DATABASE_USERNAME: 'strapi', // your username for psql
        DATABASE_PASSWORD: 'no-im-not-stupid', // your password for psql
      },
    },
  ],
};

Supporting information

I think the issue is the following: I have set watch to true, and then added ignore_watch. It somehow messes with the PM2 watching process, because now its listening to literally every change.

0|strapi   | > strapi-redacted@0.1.0 start /home/altay/redacted
0|strapi   | > strapi start
0|strapi   |

PM2      | Change detected on path .strapi-updater.json.3944530930 for app strapi - restarting
PM2      | Stopping app:strapi id:0
PM2      | App [strapi:0] exited with code [0] via signal [SIGINT]
PM2      | pid=53881 msg=process killed
PM2      | App [strapi:0] starting in -fork mode-
PM2      | App [strapi:0] online

When I comment out the ignore_watch, it starts like usual, does not listen to the change on .strapi.updater.json, but listens to public/uploads which disables uploading to my server :D Am I missing something in the documentation or this is a weird edge case due to watch: true ?

$ pm2 report
PM2        | 2021-04-23T08:10:02: PM2 log: pid=51610 msg=failed to kill - retrying in 100ms
PM2        | 2021-04-23T08:10:02: PM2 log: pid=51610 msg=failed to kill - retrying in 100ms
PM2        | 2021-04-23T08:10:02: PM2 log: pid=51610 msg=failed to kill - retrying in 100ms
PM2        | 2021-04-23T08:10:02: PM2 log: pid=51610 msg=failed to kill - retrying in 100ms
PM2        | 2021-04-23T08:10:03: PM2 log: pid=51610 msg=failed to kill - retrying in 100ms
PM2        | 2021-04-23T08:10:03: PM2 log: pid=51610 msg=failed to kill - retrying in 100ms
PM2        | 2021-04-23T08:10:03: PM2 log: pid=51610 msg=failed to kill - retrying in 100ms
PM2        | 2021-04-23T08:10:03: PM2 log: pid=51610 msg=failed to kill - retrying in 100ms
PM2        | 2021-04-23T08:10:03: PM2 log: pid=51610 msg=failed to kill - retrying in 100ms
PM2        | 2021-04-23T08:10:03: PM2 log: pid=51610 msg=failed to kill - retrying in 100ms
PM2        | 2021-04-23T08:10:03: PM2 log: pid=51610 msg=failed to kill - retrying in 100ms
PM2        | 2021-04-23T08:10:03: PM2 log: pid=51610 msg=failed to kill - retrying in 100ms
PM2        | 2021-04-23T08:10:03: PM2 log: pid=51610 msg=failed to kill - retrying in 100ms
PM2        | 2021-04-23T08:10:03: PM2 log: pid=51610 msg=failed to kill - retrying in 100ms
PM2        | 2021-04-23T08:10:04: PM2 log: pid=51610 msg=failed to kill - retrying in 100ms
PM2        | 2021-04-23T08:10:04: PM2 log: Process with pid 51610 still alive after 1600ms, sending it SIGKILL now...
PM2        | 2021-04-23T08:10:04: PM2 log: App [strapi:0] exited with code [0] via signal [SIGKILL]
PM2        | 2021-04-23T08:10:04: PM2 log: pid=51610 msg=process killed
PM2        | 2021-04-23T08:10:04: PM2 log: App [strapi:0] starting in -fork mode-
PM2        | 2021-04-23T08:10:04: PM2 log: App [strapi:0] online
Shnass commented 3 years ago

hi! wanna know if you have figured out how to deal with watch/ignore_watch, since I still failing to. As I see most of the issues here remains unanswered, I feel it would be much quicker to ask someone directly.

module.exports = {
  apps : [{
    "name":"frontend",
    "cwd":"./2senses",
    "script":"gatsby",
    "args":"build",
    "watch":["src", "./src"],
    "ignore_watch" : ["[\/\\]\./", "./node_modules", "./public", "node_modules", "public"],
      "watch_options": {
      "followSymlinks": false
    }
  },
  {
    "name":"backend",
    "cwd":"./cms",
    "script":"strapi",
    "args":"start",
  },
  {
      "name":"mailserver",
      "cwd":"./sender",
      "script":"nodemon",
      "args":"nodemailer",
  }
  ],
}

this is how my ecosystem.config.js looks, still my frontend is rebuilding like a crazy one (1000 rebuilds since yesterday's evening).