pm2 --ignore-watch not working

时间:2016-02-23 14:14:32

标签: node.js express pm2

我一直在使用pm2一段时间了。最近,我需要在我的Express4项目中添加一个名为“actionLog”的自定义日志目录。由于它是一个使用日志文件更新的目录,我不希望pm2在日志文件更改时重新启动应用程序,我希望pm2忽略观看该目录。将pm2更新为最新版本后,这是我使用的命令:

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

我通过pm2日志获得以下错误:

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

我也尝试过使用命令:

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

这也产生了同样的错误。

一旦我有了正确的ignore-watch参数,我将更新用于启动pm2的json配置文件。目前,将此配置文件与ignore-watch一起使用也会导致错误,但不是如上所述的详细堆栈跟踪,我只在pm2日志中看到以下内容:

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

我查看了一些忽略观察问题的报告,例如:

不幸的是,我仍然被困住了。有什么想法吗?

3 个答案:

答案 0 :(得分:1)

即使错误是由ignore-watch触发的,它们也不是由它引起的。以下命令修复了该问题:

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

我在这里找到了这个解决方案:https://stackoverflow.com/a/32600959/2234029

我也尝试了“npm重复数据删除” - 这个线程的建议 - 没有帮助。

答案 1 :(得分:1)

您有两种选择:

  1. 增加系统inotify max watch limit:
    echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
    1. 通过另外忽略node_modules来尝试减少观察次数:
      pm2 start bin/www --watch --ignore-watch="actionLog node_modules"
    2. 如果您没有sudo权限,则选项2适合您。

答案 2 :(得分:-1)

我认为它是ignore_watch,即带下划线