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

时间:2014-01-09 22:33:24

标签: node.js npm chef hang chef-recipe

我在使用厨师食谱运行npm install时遇到问题。当我从命令行运行它时,它会在一分钟内完成,只有一些警告与package.json no repository field相关(这应该是无害的)。但是当我从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小时,直到大厨shellout注册超时并显示致命错误。 {-1}}将显示当Chef-client仍在运行时npm仍在运行,并且中断chef-client将导致npm从进程列表中消失,这表明npm仍然认为它仍然在做有意义的工作,至少。 (另一方面,当我遇到连接问题时,我倾向于问this question。这个ps -e很可能是另一个问题的根本问题,但我认为他们需要单独考虑。)

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

npm install

我是否正确地认为|| (退出0)抛出主厨ShellOut提供商检测成功退出?我有什么可以做的吗?

编辑2:主厨刚从设置[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 的运行中超时,但仍然只获得有关超时的日志信息。

-l debug

但是!另一个节点在约5分钟后成功完成,并在[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 ---- 文件中包含此内容:

npm-run.log

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

2 个答案:

答案 0 :(得分:5)

好吧,我终于摘掉了我的白痴帽子,在正确的地方寻找原木。该命令甚至说2> builderror.log,所以你认为对于那个名字的文件而言只需find就足够了,但我仍然没有想到。这非常令人沮丧,因为node-gyp命令显然内置于kerberos源代码中,它默默地隐藏来自任何调用进程的错误(如Chef或任何其他可能需要自动进行npm安装的构建工具)。

这就是它所说的内容(一遍又一遍地大约~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用户运行,但它仍在尝试写入{{ 1}}作为/root用户!对此有些不妥,因为root很有权拥有该目录。

root

起初,我认为我只需要修复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 目录上的权限,但我认为这将对node-gyp开发人员进行跟进。

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

更新我最终解决了这个问题,让npm安装以root身份运行,然后/home/nodejs'和'chown'安装了已安装的文件。我用于此的Chef资源块看起来像这样:

chmod

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

答案 1 :(得分:1)

这个问题在我的OSX上挂了大约10分钟(感觉就像),但它设法完成了。我使用过&sudo npm install'从WebStorm IDE内部启动的终端安装mongoose。 (Haven没有尝试没有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

相关问题