【问题标题】:pm2 --ignore-watch not workingpm2 --ignore-watch 不工作
【发布时间】:2016-06-05 10:14:39
【问题描述】:

我已经使用 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

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

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

【问题讨论】:

    标签: node.js express pm2


    【解决方案1】:

    我认为是ignore_watch 即带下划线

    【讨论】:

    【解决方案2】:

    事实证明,即使错误是由 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 dedupe” - 正如该线程上所建议的那样 - 这没有帮助。

    【讨论】:

      【解决方案3】:

      你有两个选择:

      1. 提高系统 inotify 最大观看限制:
        echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf &amp;&amp; sudo sysctl -p

      1. 通过另外忽略node_modules 来尝试减少观看次数:
        pm2 start bin/www --watch --ignore-watch="actionLog node_modules"

      如果您没有 sudo 权限,选项 2 适合您。

      【讨论】:

        猜你喜欢
        • 2019-08-27
        • 1970-01-01
        • 2015-12-26
        • 2016-06-07
        • 1970-01-01
        • 1970-01-01
        • 2017-12-04
        • 2011-08-27
        • 2018-11-14
        相关资源
        最近更新 更多