Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

  • https://github.com/Unitech/PM2/issues/1288
  • https://github.com/Unitech/PM2/issues/918
  • https://github.com/Unitech/PM2/issues/1275
  • How to auto reload project nodejs use pm2
  • Express 4 + pm2 watch not working

Unfortunately, I am still stuck. Any ideas?

like image 976
woz Avatar asked Oct 31 '22 08:10

woz


1 Answers

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.

like image 104
Per Avatar answered Nov 15 '22 05:11

Per