'pm2 --ignore-watch not working

I have been using pm2 for some time now. Recently, I needed to add a custom log directory to my Express4 project called "actionLog". Since it is a directory that gets updated with log files and I don't want pm2 to restart the app on log file changes, I wanted pm2 to ignore watching that directory. After updating pm2 to latest, here is the command I used:

pm2 start app.js --watch --ignore-watch="actionLog"

I get the following error streaming through the pm2 logs:

PM2 Error: watch ENOSPC
PM2     at exports._errnoException (util.js:746:11)
PM2     at FSWatcher.start (fs.js:1172:11)
PM2     at Object.fs.watch (fs.js:1198:11)
PM2     at createFsWatchInstance (/usr/local/lib/node_modules/pm2/node_modules/chokidar/lib/nodefs-handler.js:37:15)
PM2     at setFsWatchListener (/usr/local/lib/node_modules/pm2/node_modules/chokidar/lib/nodefs-handler.js:80:15)
PM2     at EventEmitter.NodeFsHandler._watchWithNodeFs (/usr/local/lib/node_modules/pm2/node_modules/chokidar/lib/nodefs-handler.js:228:14)
PM2     at EventEmitter.NodeFsHandler._handleFile (/usr/local/lib/node_modules/pm2/node_modules/chokidar/lib/nodefs-handler.js:255:21)
PM2     at EventEmitter.<anonymous> (/usr/local/lib/node_modules/pm2/node_modules/chokidar/lib/nodefs-handler.js:468:21)
PM2     at FSReqWrap.oncomplete (fs.js:95:15)
PM2 Error: watch ENOSPC
PM2     at exports._errnoException (util.js:746:11)
PM2     at FSWatcher.start (fs.js:1172:11)
PM2     at Object.fs.watch (fs.js:1198:11)
PM2     at createFsWatchInstance (/usr/local/lib/node_modules/pm2/node_modules/chokidar/lib/nodefs-handler.js:37:15)
PM2     at setFsWatchListener (/usr/local/lib/node_modules/pm2/node_modules/chokidar/lib/nodefs-handler.js:80:15)
PM2     at EventEmitter.NodeFsHandler._watchWithNodeFs (/usr/local/lib/node_modules/pm2/node_modules/chokidar/lib/nodefs-handler.js:228:14)
PM2     at EventEmitter.NodeFsHandler._handleFile (/usr/local/lib/node_modules/pm2/node_modules/chokidar/lib/nodefs-handler.js:255:21)
PM2     at EventEmitter.<anonymous> (/usr/local/lib/node_modules/pm2/node_modules/chokidar/lib/nodefs-handler.js:468:21)
PM2     at FSReqWrap.oncomplete (fs.js:95:15)
PM2 Error: watch ENOSPC

I have also tried using the command:

pm2 start bin/www --watch --ignore-watch="actionLog"

This also generated the same error.

Once I have the correct ignore-watch parameter, I will update the json config file I use for starting pm2. At the moment, using this config file with the ignore-watch is also causing errors, but instead of a detailed stack trace as above, I only see the following in the pm2 logs:

PM2: 2016-02-23 04:05:34: Starting execution sequence in -fork mode- for app name:aadm id:2
PM2: 2016-02-23 04:05:34: App name:aadm id:2 online
PM2: 2016-02-23 04:05:35: Change detected on path actionLog/userAction.log for app aadm - restarting
PM2: 2016-02-23 04:05:35: Stopping app:aadm id:2
PM2: 2016-02-23 04:05:35: App name:aadm id:2 exited with code SIGTERM
PM2: 2016-02-23 04:05:35: Process with pid 5102 killed
PM2: 2016-02-23 04:05:35: Starting execution sequence in -fork mode- for app name:aadm id:2
PM2: 2016-02-23 04:05:35: App name:aadm id:2 online

I have looked at some of the reports of ignore-watch problems such as:

Unfortunately, I am still stuck. Any ideas?



Solution 1:[1]

Turns out even though the errors were triggered by ignore-watch, they were not caused by it. The following command fixed the issue:

echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p

I found this solution here: https://stackoverflow.com/a/32600959/2234029

I also tried "npm dedupe" -as suggested on that thread- which didn't help.

Solution 2:[2]

You have two options:

  1. Increase the systems inotify max watch limit:
    echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p

or

  1. Try to decrease you watch count by additionally ignoring node_modules:
    pm2 start bin/www --watch --ignore-watch="actionLog node_modules"

If you don't have sudo rights option 2 is for you.

Solution 3:[3]

I had the same problem. It was driving me crazy, then I discovered there were many sessions of PM2 running in my system. A command like ps aux | grep pm2 shows you all instances running.

So I killed manually each instance (shown by the command above) one by one with:

kill -9 <pid1> <pid2> <pid3> <...>

At last I restarted the process:

pm2 start ecosystem.config.js

and then everything went working smoothly as written in my config file (without any "watch" option).

The actual question is: why those processes where running on my server, but I can't answer this.

Solution 4:[4]

I think it is ignore_watch ie with an underline

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Community
Solution 2
Solution 3 Jacopo Pace
Solution 4 akc42