Pm2: Refactor Watch System

Created on 12 Jan 2017  Β·  31Comments  Β·  Source: Unitech/pm2

Pending Deletion Need More Data

Most helpful comment

@AamuLumi, I'm a maintainer on micromatch, which is used in anymatch. If you're trying to ignore anything in the src/modules/**/app folder(s), then you could try:

'src/modules/**/app/**'
// or
'src/modules/**/app/**/*'

Also, for the second pattern (and the first if there are any "dot" files), use the watch_options property specified here to ensure files and folders that start with a dot . are also captured in the glob:

watch_options: {
  dot: true
}

I hope this helps. I don't have anything available to test with right now, so I'm showing what I think should work.

All 31 comments

Be able to run a command each time a file is updated #2685

whats the status of this work log?

Its in the backlog, that means we aim to do this as soon as we can.

Seems that currently it works as good as you ignore a folder or a file, but globs don't.

Restarting reset the watch option with ecosystem file #2920

Any info on this?
We have a need to run eslint each time change with watch is detected, before reload.

@vmarchaud ☝️ Is this work still in the "backlog"? An update would be appreciated, thanks.

Having the watch not working on restart and if my app status is "errored" it also stops watching.

Are there any updates on this issue?

Hi ! Is there some news about this issue ? ignore_watch is still unusable (because completly bugged) and it's a major problem for all developers with at least 2 servers.

@AamuLumi I don't get how ignore_watch is "unusable" and "completly bugged". Some examples that may help you setting it correctly: https://github.com/Unitech/pm2/search?utf8=%E2%9C%93&q=ignore_watch&type=

I tested all possible patterns accepted by anymatch (as mentioned in the documentation of chokidar mentioned in the documentation of pm2). When I spend 2 hours of time to test all possible paths and nothing works, sorry, but this is "completly bugged". Perhaps the lack of real documentation is the true issue, yeah.

Here's some tests I've done :

"src/modules/**/app"
"src\/modules\/.*\/app"
"src\/modules\/[a-zA-Z]*\/app"
"src/modules"
"src\/modules"

All these cases cannot ignore the file src/modules/data/app/something/aFile.ts.

Got the same problem with :

".cache-loader"
".cache-loader/*"
".cache-loader/*.json"
".cache-loader\/.*"

Nothing ignore the file .cache-loader/xxx.json.

@AamuLumi, I'm a maintainer on micromatch, which is used in anymatch. If you're trying to ignore anything in the src/modules/**/app folder(s), then you could try:

'src/modules/**/app/**'
// or
'src/modules/**/app/**/*'

Also, for the second pattern (and the first if there are any "dot" files), use the watch_options property specified here to ensure files and folders that start with a dot . are also captured in the glob:

watch_options: {
  dot: true
}

I hope this helps. I don't have anything available to test with right now, so I'm showing what I think should work.

You're a genius dude ! Thanks a lot !

Note : for the second pattern, dot option isn't needed. I think there was a bug in my infrastructure : it seems Docker stopped refreshing my configuration files when I was working on ignore_watch. All works perfectly now.

My bad, and sorry for blaming too fast ignore_files. :/

When I attempt to use the watch mode, I get extra processes that are still running and blocking my ports. I have tried moving the chokidar watching into my script, disabling it in pm2, and triggering a process.exit when files change, but that doesn't work either. The extra processes seem to come during the startup rather than failure to exit.

I end up having to use "pm2 delete ecosystem.json" followed by "kill -9 $PROCESS_IDS" and "pm2 start ecosystem.json". It's very tedious and really defeats much of the purpose of using pm2 during development. If there's any update or suggestion to make the development flow more convenient, that would be greatly appreciated.

It doesn't stem from ignored watch or anything like that - the correct files are ignored whether I let pm2 handle the watching or configure it myself in my application.

Ignore Watch is bugged. I'm currently using Realm. My ignore watch is:

"ignore_watch" : [".sailsrc", ".tmp", "views", "assets", "node_modules", ".git", ".DS_Store", "realm-object-server"],

Only files in views and realm-object-server folders change on boot. PM2 seems to continuously restart the server.

i cant get this fu* ignore to work, how could this be so hard!???
i am using escosystem file named "ecosystem.dev.config.js" on Windows10 with this rule
ignore_watch: ["*.json"]
i have tried with many many other patterns....

FYI - I did notice my app was crashing which was causing pm2 to restart it. I fixed the crash, but ignore watch is still bugging out. Everyone that is experiencing auto restarts, please check by running your app via node first to see if it runs fine.

I seem to be having the same problem. I want to ignore all and any updates that are in the "clients" directory. Here some patterns I have tried:

['./client/', './node_modules/']
['/client/', '/node_modules/']
['client/', 'node_modules/']
['client', 'node_modules']

In testing I have "pm2 monit" up in my terminal and I see in the logs that it is detecting a change in client/components/ and so on to the file located there. Spent about 2 hours on this so far and it still does not ignore the client directory.

I'm encountering a similar problem. When I add the node_modules directory to the ignore-watch it still detects changes

Same here, is there a fix for this?

Still there !
Is anyone working on this bug ?

PM2 v4.0 will fix that
Could you please try the development version and let me know if that issue has been fixed:

npm install Unitech/pm2#development -g
pm2 update

PM2 v4.0 will fix that
Could you please try the development version and let me know if that issue has been fixed:

npm install Unitech/pm2#development -g
pm2 update

This did not work.. pm2 is still restarting when some ignored folders content changes

glad to know i'm not the only one annoyed with this πŸ˜…

I also have this issue. Windows 10 pro, Node v10.15.3, PM2 3.5.1 (also tried
4.0.0-beta-7). I'm starting pm2 without a watch, everything works fine until app reaches max memory limit, then app restarts and I get an error: "address already in use". If you try pm2 stop, then it stops and starts again. An only possible way to kill app is to make pm2 delete id and then kill the process manually.

Yea, I'm currently trying to deploy on Heroku and keep running into

"Something is already running on port 47607."

I can't tell if its because im using windows or not. I changed mine to development node and now I'm getting this.
PM2 log: App [PrO:7] exited with code [0] via signal [SIGINT]

ignore_watch works perfectly.
I can't reproduce the issues you are talking about guys, if you could setup a repo so I can try to reproduce its welcome.

Try:

mkdir watch-test
cd watch-test

npm init
npm install express

mkdir clients
touch clients/dontwatch.js

mkdir towatch
echo "setInterval(() => console.log('hey'), 1000)" > towatch/watchme.js

ecosystem.config.js:

module.exports = {
  apps : [{
    name: 'API',
    script: 'towatch/watchme.js',
    watch: true,
    ignore_watch: ['node_modules', 'clients']
  }]
}

Then

pm2 start ecosystem.config.js
touch node_modules/shouldnotrestart
touch clients/touchme.js

No restart at all but if I change the script towatch/watchme.js I get a auto restart from pm2

I have the same problem. What am I doing wrong?
My project:

  • root-folder
    |-- src
    |-- node_modules
    |-- package.json
    |-- index.js
    |-- ecosystem.config.js

i have ecosystem.config.js:

module.exports = {
  apps : [{
    name: 'bot',
    script: 'index.js',
    log_date_format: 'YYYY-MM-DD HH:mm Z',
   // error_file: '$HOME/.pm2/logs/XXXerr.log',
   // out_file: '$HOME/.pm2/logs/XXXout.log',
    // Options reference: https://pm2.io/doc/en/runtime/reference/ecosystem-file/
    args: 'one two',
    instances: 1,
    autorestart: true,
    watch: true,
    ignore_watch: ['node_modules'],
    max_restarts: 10,
    max_memory_restart: '500M',
    env: {
      NODE_ENV: 'development'
    },
    env_production: {
      NODE_ENV: 'production'
    }
  }],
}
pm2 start ecosystem.config.js
β”Œβ”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ id β”‚ name                    β”‚ version β”‚ mode    β”‚ pid      β”‚ uptime β”‚ β†Ί    β”‚ status   β”‚ cpu      β”‚ mem      β”‚ user     β”‚ watching β”‚
β”œβ”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ 0  β”‚ bot                     β”‚ 0.3.0   β”‚ cluster β”‚ 5747     β”‚ 0s     β”‚ 67   β”‚ online   β”‚ 0%       β”‚ 30.8mb   β”‚ joсker    β”‚ enabled  β”‚
β””β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

i change file index.js, but the server does not restart
pm2 logs

[TAILING] Tailing last 15 lines for [all] processes (change the value with --lines option)
/home/bot/.pm2/pm2.log last 15 lines:

PM2        | 2019-11-06T22:23:45: PM2 log: App [bot:0] starting in -cluster mode-
PM2        | 2019-11-06T22:23:45: PM2 log: App [bot:0] online

After pm2 restart ecosystem.config.js all changes accepted

Is the issue solved? There is no solution mentioned

@Unitech we are still experiencing "address already in use"-related errors due to an unclean/too-fast restart when there's (usually multiple) changes detected; so this issue definitely does not appear to be solved.
running pm2 4.5.0 (last release)

Was this page helpful?
0 / 5 - 0 ratings