Node.js Chef客户端挂起在节点gyp重建处的npm安装

Node.js Chef客户端挂起在节点gyp重建处的npm安装,node.js,npm,chef-infra,freeze,chef-recipe,Node.js,Npm,Chef Infra,Freeze,Chef Recipe,我在从厨师菜谱运行npm安装时遇到问题。当我从命令行运行它时,它在不到一分钟的时间内就完成了,只出现了一些与相关的警告(这应该是无害的)。但是,当我从chef运行它时,它与返回到命令行的最后一行输出挂起,如下所示: * execute[npm-install-app] action run 配方中的哪个资源块: execute "npm-install-app" do cwd "#{home}/#{prefix}#{app}" command "npm --registry #{pri

我在从厨师菜谱运行
npm安装时遇到问题。当我从命令行运行它时,它在不到一分钟的时间内就完成了,只出现了一些与相关的警告(这应该是无害的)。但是,当我从chef运行它时,它与返回到命令行的最后一行输出挂起,如下所示:

* 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至少仍认为自己仍在做有意义的工作。(顺便说一句,当我遇到连接问题时,我倾向于问。这个
npm安装
很可能是另一个问题的根本问题,但我认为它们值得单独考虑。)

编辑:使用
-l调试运行chef客户端
会向
/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
我认为| | |(出口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'

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

我终于摘下我的白痴帽子,在正确的地方寻找原木。该命令甚至会显示
2>builderror.log
,因此您可能认为这足够作为一个提示,只需
查找该名称的文件,但我仍然没有想到。这是非常令人沮丧的,因为node-gyp命令显然内置于kerberos源代码中,并且它在任何调用过程(如Chef或任何其他可能希望自动安装npm的构建工具)中都会隐藏错误

下面是它所说的(一次又一次,大约350MB,这是一个有趣的小问题!幸好我的厨师食谱删除了每次跑步时使用的目录,否则这可能会变得更难诊断):

奇怪的是node gyp正在处理这个位置附近的文件:
/home/nodejs/my app/node_modules/mongoose-q/node_modules/mongoose/node_modules/mongodb/node_modules/kerberos/
,我的npm安装命令正在以
nodejs
用户的身份运行,但是它仍然试图以
root
用户的身份写入
/root
!这肯定有什么问题,因为
root
darn well拥有该目录的权限

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命令bare,它会正常工作

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

  # 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在权限部门的缺点,如果我在这方面得到直接的回应,我将继续追问并发布另一个答案。

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

-
> kerberos@0.0.3安装…/Documents/../node\u modules/mongoose/node\u modules/mongodb/node\u modules/kerberos
>(节点gyp rebuild 2>builderror.log)| |(退出0)
\
> bson@0.2.12安装…/Documents/../node_modules/mongoose/node_modules/mongodb/node_modules/bson
>(节点gyp rebuild 2>builderror.log)| |(退出0)
>
CXX(目标)发布/obj.target/bson/ext/bson.o
SOLINK_模块(目标)发布/bson.node
SOLINK_模块(目标)发布/bson.node:完成
mongoose@3.8.17节点单元模块/猫鼬
├── 正则表达式-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(可读-stream@1.0.32, kerberos@0.0.3, bson@0.2.12)

$ls-al

您找到解决方案了吗?我看不到任何明显的原因。@sethvargo我还没有取得任何进展。我目前正在尝试从
节点gyp rebuild
过程中捕获更多日志,但没有提及任何相关内容。我可能得去潜入源代码,或者试试alias magic.Cool。我很高兴你能理解其中的大部分
  # 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
-
> 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)