5

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?

Community
  • 1
  • 1
woz
  • 197
  • 1
  • 3
  • 10

4 Answers4

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.

Per
  • 393
  • 1
  • 4
  • 12
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.

Community
  • 1
  • 1
woz
  • 197
  • 1
  • 3
  • 10
0

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.

Jacopo Pace
  • 460
  • 7
  • 14
-2

I think it is ignore_watch ie with an underline

akc42
  • 4,893
  • 5
  • 41
  • 60
  • 2
    The command line parameter is --ignore-watch. Please see: http://pm2.keymetrics.io/docs/usage/quick-start/ . If you use it in the config file, then ignore_watch is used. For that, please see: http://pm2.keymetrics.io/docs/usage/watch-and-restart/ – woz Feb 23 '16 at 19:55
  • This command attribute does not exisits – Ali Hussnain - alichampion May 24 '22 at 11:13