pm2 --ignore-watch不起作用

woz*_*woz 5 node.js express pm2

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

pm2 start app.js --watch --ignore-watch="actionLog"
Run Code Online (Sandbox Code Playgroud)

我在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
Run Code Online (Sandbox Code Playgroud)

我也尝试使用以下命令:

pm2 start bin/www --watch --ignore-watch="actionLog"
Run Code Online (Sandbox Code Playgroud)

这也产生了相同的错误。

一旦有了正确的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
Run Code Online (Sandbox Code Playgroud)

我看了一些忽略监视问题的报告,例如:

不幸的是,我仍然被困住。有任何想法吗?

woz*_*woz 1

事实证明,尽管错误是由忽略监视触发的,但它们并不是由它引起的。以下命令修复了该问题:

echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
Run Code Online (Sandbox Code Playgroud)

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

我还尝试了“npm dedupe” - 正如该线程所建议的 - 这没有帮助。