挂在npm上的厨师客户端安装在node-gyp重build

我遇到了一个从厨师食谱运行npm install的问题。 当我从命令行运行它,它在一分钟内完成罚款,只有一些警告与package.json没有储存库字段 (这应该是无害的)。 但是,当我从厨师运行它,它挂起最后一行输出回到命令行,如下所示:

 * 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

正如你所看到的,我将输出redirect到一个文件,使用> 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服务器上打包的应用程序版本。

它会在这种状态下呆两个小时,直到厨师大人登记超时,并显示一个致命的错误。 ps -e会显示npm在主厨客户端仍在运行时仍在运行,而中断主厨客户端会导致npm从进程列表中消失,这表明npm至less仍认为它仍在做有意义的工作。 (在附注中,当我遇到连接问题时,我倾向于提出这个问题 ,这个npm install是另一个问题的根本问题,但我认为他们需要单独考虑。

编辑:使用-l debug运行chef-client会在/var/log/chef/client.log文件中添加less量的信息,这基本上证实了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)正在甩掉厨师的ShellOut提供商检测成功退出? 有什么我可以做的吗?

编辑2:厨师刚从超时运行-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实例上。 也许有工作和破碎的服务器上的主目录之间的权限差异…我将调查该angular度。

那么我终于把我的白痴帽子,并在正确的地方寻找日志。 该命令甚至说2> builderror.log ,所以你会认为这只是一个提示,只是find一个名称的文件,但它仍然没有发生在我身上。 这是非常令人沮丧的,因为node-gyp命令显然是内置在kerberos源代码中的,它默默地隐藏了来自任何调用进程(比如Chef或者其他可能想要自动安装npm-install的构build工具)的错误。

这是它所说的(一遍又一遍约350 MB,因此有趣的小挂!好东西我厨师的食谱是删除每个运行使用的目录,或者这可能已经更难以诊断):

 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用户身份写入/root ! 一些东西必须与此不一致,因为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开发者。

至less这解释了为什么如果我作为一个不同的用户(谁拥有sudo权限)运行npm-install命令裸机,它的工作原理。

更新:我最终通过让npm install作为root运行,然后chownchmod '安装的文件来解决这个问题。 我使用的厨师资源块看起来像这样:

  # 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内部的terminal安装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