在 node-gyp 重建时挂在 npm install 上的厨师客户端

Posted

技术标签:

【中文标题】在 node-gyp 重建时挂在 npm install 上的厨师客户端【英文标题】:Chef client hanging on npm install at node-gyp rebuild 【发布时间】:2014-01-28 17:40:41 【问题描述】:

我在从厨师食谱运行 npm install 时遇到问题。当我从命令行运行它时,它会在不到一分钟的时间内完成,只有一些与package.json no repository field 相关的警告(应该是无害的)。但是当我从厨师运行它时,它会挂起最后一行输出回到命令行,如下所示:

* execute[npm-install-app] action run

配方中的这个资源块是什么:

execute "npm-install-app" do
  cwd "#home/#prefix#app"
  command "npm --registry #priv['url']:#priv['port']#priv['path'] install --cache #home/.npm --tmp #home/tmp > npm-run.log 2>&1"
  user node['nodejs']['user']
  action :run
end

其中#home 扩展为/home/nodejs,用户为nodejs

如您所见,我将输出重定向到一个文件到一个带有> npm-run.log 2>&1 的文件。输出文件获取写入它的 npm install 命令的输出(与命令行不同),最后出现的是这样的:

-- a bunch of 200's and 304s, like this --
npm http 304 http://my.private.npm.amazonaws.com/registry/_design/app/_rewrite/esprima

kerberos@0.0.3 install /home/nodejs/my-app/node_modules/mongoose-q/node_modules/mongoose/node_modules/mongodb/node_modules/kerberos
(node-gyp rebuild 2> builderror.log) || (exit 0)

kerberos 是我们依赖的一个模块的依赖项,但我们自己并没有使用 kerberos。我从其他来源收集到 npm 正在运行 node-gyp 以编译在 npm 服务器上不可用的应用程序版本。

它将保持该状态 2 小时,直到 Chef shellout 注册超时并显示致命错误。 ps -e 将在 chef-client 仍在运行时显示 npm 仍在运行,并且中断 chef-client 将导致 npm 从进程列表中消失,这表明 npm 至少仍然认为它仍在做有意义的工作。 (附带说明,当我遇到连接问题时,我倾向于问this question。这个npm install 很可能是另一个问题的根本问题,但我认为它们值得单独考虑.)

编辑: 使用-l debug 运行chef-client 会将少量信息添加到/var/log/chef/client.log 文件中,这基本上确认npm install 命令是最后一个资源在挂起之前执行:

[2014-01-09T22:49:28+00:00] INFO: Processing execute[npm-install-app] action run (my-app::default line 111)
[2014-01-09T22:49:28+00:00] DEBUG: Platform ubuntu version 12.04 found

我认为 || 是对的吗? (exit 0) 是否让 Chef ShellOut 提供程序检测到成功退出?有什么我可以做的吗?

编辑 2: Chef 刚刚在设置了 -l debug 的情况下运行超时,但仍然只获得有关超时的日志信息。

[2014-01-10T00:26:56+00:00] ERROR: execute[npm-install-app] (my-app::default line 111) had an error: Mixlib::ShellOut::CommandTimeout: command timed out:
---- Begin output of npm --registry http:my.private.npm.amazonaws.com:5984/registry/_design/app/_rewrite install --cache /home/nodejs/.npm --tmp /home/nodejs/tmp > npm-run.log 2>&1 ----
STDOUT:
STDERR:
---- End output of npm --registry http://ec2-54-221-190-191.compute-1.amazonaws.com:5984/registry/_design/app/_rewrite install --cache /home/nodejs/.npm --tmp /home/nodejs/tmp > npm-run.log 2>&1 ----

但是!大约 5 分钟后,另一个节点刚刚成功完成,并且在 npm-run.log 文件中有此内容:

> kerberos@0.0.3 install /home/nodejs/spicoli-authorization/node_modules/mongoose-q/node_modules/mongoose/node_modules/mongodb/node_modules/kerberos
> (node-gyp rebuild 2> builderror.log) || (exit 0)

make: Entering directory `/home/nodejs/spicoli-authorization/node_modules/mongoose-q/node_modules/mongoose/node_modules/mongodb/node_modules/kerberos/build'
  SOLINK_MODULE(target) Release/obj.target/kerberos.node
  SOLINK_MODULE(target) Release/obj.target/kerberos.node: Finished
  COPY Release/kerberos.node
make: Leaving directory `/home/nodejs/spicoli-authorization/node_modules/mongoose-q/node_modules/mongoose/node_modules/mongodb/node_modules/kerberos/build'

我想不出为什么会有如此巨大的性能差异,两台服务器都运行在亚马逊小型 ec2 实例上。也许工作服务器和损坏服务器上的主目录之间存在权限差异......我会从这个角度进行调查。

【问题讨论】:

您找到解决方案了吗?我没有看到任何明显会导致这种情况的东西。 @sethvargo 我还没有取得任何进展。我目前正在尝试找到一种从node-gyp rebuild 进程中捕获更多日志的方法,但their documentation 没有提及任何相关内容。我可能需要深入研究源代码,或者尝试一些别名魔法。 【参考方案1】:

这个问题在我的 OSX 上挂了大约 10 分钟(感觉就像),但它设法完成了。我使用“sudo npm install”从 WebStorm IDE 中启动的终端安装 mongoose。 (没有 sudo 没试过。)

-
> kerberos@0.0.3 install .../Documents/.../node_modules/mongoose/node_modules/mongodb/node_modules/kerberos
> (node-gyp rebuild 2> builderror.log) || (exit 0)

\
> bson@0.2.12 install .../Documents/.../node_modules/mongoose/node_modules/mongodb/node_modules/bson
> (node-gyp rebuild 2> builderror.log) || (exit 0)

<<<< HERE IS THE STRANGE HANGING >>>>


  CXX(target) Release/obj.target/bson/ext/bson.o
  SOLINK_MODULE(target) Release/bson.node
  SOLINK_MODULE(target) Release/bson.node: Finished
mongoose@3.8.17 node_modules/mongoose
├── regexp-clone@0.0.1
├── hooks@0.2.1
├── mpath@0.1.1
├── mpromise@0.4.3
├── ms@0.1.0
├── muri@0.3.1
├── sliced@0.0.5
├── mquery@0.8.0 (debug@0.7.4)
└── mongodb@1.4.9 (readable-stream@1.0.32, kerberos@0.0.3, bson@0.2.12)

$ ls -al

【讨论】:

您似乎遇到了同样的问题。你看过builderror.log的内容吗?如果错误消息匹配,您是否尝试过我上面回答中的步骤?如果消息不匹配,您可能需要Ask a new Question。【参考方案2】:

好吧,我终于脱下我的白痴帽子,在正确的地方寻找日志。该命令甚至说2&gt; builderror.log,因此您认为对于该名称的文件,只需find 就足够了,但我仍然没有想到。这非常令人沮丧,因为 node-gyp 命令显然是内置在 kerberos 源代码中的,它会默默地隐藏任何调用进程(如 Chef 或任何其他可能想要自动 npm-install 的构建工具)的错误。

这就是它所说的(一遍又一遍地大约 350 MB,因此有趣的小挂起!幸好我的 Chef 食谱删除了每次运行时使用的目录,否则这可能更难诊断):

gyp WARN EACCES attempting to reinstall using temporary dev dir "/root/tmp/.node-gyp"
gyp WARN EACCES user "root" does not have permission to access the dev dir "/root/tmp/.node-gyp/0.10.22"

奇怪的是,node-gyp 正在处理这个位置周围的文件:/home/nodejs/my-app/node_modules/mongoose-q/node_modules/mongoose/node_modules/mongodb/node_modules/kerberos/,而我的 npm install 命令正在以 nodejs 用户身份运行,但它仍在尝试以 @ 身份写入 /root 987654327@用户!这肯定有问题,因为root darn 很好地拥有该目录的权限。

ubuntu@amazonaws:~$ sudo ls -la /
-- snip --
drwx------  4 root root  4096 Jan  7 22:50 root

ubuntu@amazonaws:~$ sudo ls -la /root
total 24
drwx------  4 root root 4096 Jan  7 22:50 .
drwxr-xr-x 23 root root 4096 Jan  7 22:46 ..
-rw-r--r--  1 root root 3106 Apr 19  2012 .bashrc
drwx------  2 root root 4096 Jan  7 22:50 .cache
-rw-r--r--  1 root root  140 Apr 19  2012 .profile
drwx------  2 root root 4096 Jan  7 22:46 .ssh

起初,我以为我只需要修复 /home/nodejs 目录的权限,但我认为这需要 node-gyp 开发人员跟进。

至少这解释了为什么如果我以其他用户(具有 sudo 权限)的身份运行 npm-install 命令,它可以工作。

更新:我最终解决了这个问题,让 npm install 以 root 身份运行,然后 chown'ing 和 chmod'ing 安装文件。我用于此的 Chef 资源块如下所示:

  # Recursively chown and chmod all files just created
  execute "fixup #home/#prefix#app owner" do
    command "find ./ -exec sudo chown #node[:nodejs][:user]:#node[:nodejs][:user]  +"
    cwd "#home/#prefix#app"
  end

  execute "fixup #home/#prefix#app file permissions" do
    command "find ./ -type f -exec sudo chmod 644  +"
    cwd "#home/#prefix#app"
  end

  execute "fixup #home/#prefix#app directory permissions" do
    command "find ./ -type d -exec sudo chmod 755  +"
    cwd "#home/#prefix#app"
  end

这并不能解决 node-gyp 在权限部门的缺点,如果我在这方面得到直接回应,我将继续追求并发布另一个答案。

【讨论】:

酷。我很高兴你能弄清楚大部分。不要忘记在 2 天内接受您的回答 :) 谢谢赛斯。呵呵,希望到那时我会有一个可行的解决方案:-p

以上是关于在 node-gyp 重建时挂在 npm install 上的厨师客户端的主要内容,如果未能解决你的问题,请参考以下文章

npm install jquery 在 node-gyp 重建时失败

节点 10 - npm 安装期间的“node-gyp 重建”错误

`npm install` 在 node-gyp 重建时失败,并带有`gyp:未检测到 Xcode 或 CLT 版本!`

npm install 并在 node-gyp 重建时失败,使用 ``gyp: No Xcode or CLT version detected!``` 由新的 macos catalina 更新引起

如何解决 Windows 10 上的“node-gyp 重建”问题?

Cordova / Ionic iOS 应用程序在加载插件时挂在启动屏幕上