“命令失败,状态为()".预编译资产时 [英] "Command failed with status ()" when precompiling assets

查看:155
本文介绍了“命令失败,状态为()".预编译资产时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在生产盒上编译资产时,我遇到了许多用户之类的类似问题.唯一的区别是我无法从跟踪中获得任何提示来解决问题.

I am having similiar problems like a lot of users when compiling assets on their productive box. The only difference is that I can't get any hint out of the trace to solve the problem.

rake assets:precompile RAILS_ENV=production --trace
** Invoke assets:precompile (first_time)
** Execute assets:precompile
/usr/local/rbenv/versions/1.9.3-p362/bin/ruby /usr/local/rbenv/versions/1.9.3-p362/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets --trace
** Invoke assets:precompile:all (first_time)
** Execute assets:precompile:all
** Invoke assets:precompile:primary (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke environment (first_time)
** Execute environment
** Invoke tmp:cache:clear (first_time)
** Execute tmp:cache:clear
** Execute assets:precompile:primary
rake aborted!
Command failed with status (): [/usr/local/rbenv/versions/1.9.3-p362/bin/r...]
/usr/local/rbenv/versions/1.9.3-p362/lib/ruby/1.9.1/rake/file_utils.rb:53:in `block in create_shell_runner'
/usr/local/rbenv/versions/1.9.3-p362/lib/ruby/1.9.1/rake/file_utils.rb:45:in `call'
/usr/local/rbenv/versions/1.9.3-p362/lib/ruby/1.9.1/rake/file_utils.rb:45:in `sh'
/usr/local/rbenv/versions/1.9.3-p362/lib/ruby/1.9.1/rake/file_utils_ext.rb:39:in `sh'
/usr/local/rbenv/versions/1.9.3-p362/lib/ruby/1.9.1/rake/file_utils.rb:80:in `ruby'
/usr/local/rbenv/versions/1.9.3-p362/lib/ruby/1.9.1/rake/file_utils_ext.rb:39:in `ruby'
/home/app/application/ruby/1.9.1/gems/actionpack-3.2.12/lib/sprockets/assets.rake:12:in `ruby_rake_task'
/home/app/application/ruby/1.9.1/gems/actionpack-3.2.12/lib/sprockets/assets.rake:21:in `invoke_or_reboot_rake_task'
/home/app/application/ruby/1.9.1/gems/actionpack-3.2.12/lib/sprockets/assets.rake:29:in `block (2 levels) in <top (required)>'
/usr/local/rbenv/versions/1.9.3-p362/lib/ruby/1.9.1/rake/task.rb:205:in `call'
/usr/local/rbenv/versions/1.9.3-p362/lib/ruby/1.9.1/rake/task.rb:205:in `block in execute'
/usr/local/rbenv/versions/1.9.3-p362/lib/ruby/1.9.1/rake/task.rb:200:in `each'
/usr/local/rbenv/versions/1.9.3-p362/lib/ruby/1.9.1/rake/task.rb:200:in `execute'
/usr/local/rbenv/versions/1.9.3-p362/lib/ruby/1.9.1/rake/task.rb:158:in `block in invoke_with_call_chain'
/usr/local/rbenv/versions/1.9.3-p362/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/usr/local/rbenv/versions/1.9.3-p362/lib/ruby/1.9.1/rake/task.rb:151:in `invoke_with_call_chain'
/usr/local/rbenv/versions/1.9.3-p362/lib/ruby/1.9.1/rake/task.rb:144:in `invoke'
/usr/local/rbenv/versions/1.9.3-p362/lib/ruby/1.9.1/rake/application.rb:116:in `invoke_task'
/usr/local/rbenv/versions/1.9.3-p362/lib/ruby/1.9.1/rake/application.rb:94:in `block (2 levels) in top_level'
/usr/local/rbenv/versions/1.9.3-p362/lib/ruby/1.9.1/rake/application.rb:94:in `each'
/usr/local/rbenv/versions/1.9.3-p362/lib/ruby/1.9.1/rake/application.rb:94:in `block in top_level'
/usr/local/rbenv/versions/1.9.3-p362/lib/ruby/1.9.1/rake/application.rb:133:in `standard_exception_handling'
/usr/local/rbenv/versions/1.9.3-p362/lib/ruby/1.9.1/rake/application.rb:88:in `top_level'
/usr/local/rbenv/versions/1.9.3-p362/lib/ruby/1.9.1/rake/application.rb:66:in `block in run'
/usr/local/rbenv/versions/1.9.3-p362/lib/ruby/1.9.1/rake/application.rb:133:in `standard_exception_handling'
/usr/local/rbenv/versions/1.9.3-p362/lib/ruby/1.9.1/rake/application.rb:63:in `run'
/usr/local/rbenv/versions/1.9.3-p362/bin/rake:32:in `<main>'
Tasks: TOP => assets:precompile

实际上没有状态码,只有失败.如果直接或通过bundle exec调用rake,也没有任何区别.

There is effectively no status code, just the fail. It also does not make any difference if I call rake directly or via bundle exec.

关于环境 具有全局rbenv安装的debian squeeze框(如从跟踪中看到的那样,为/usr/local/rbenv). Ruby 1.9.3 2012-12-25补丁程序级别362.

About the environment debian squeeze box with a global rbenv installation (/usr/local/rbenv like you can see from the trace). Ruby 1.9.3 2012-12-25 patchlevel 362.

对此有任何提示/想法吗?

Any hints / ideas on this?

推荐答案

我将自己回答这个问题,因为我可以或多或少地解决它.如果有人有其他内容,请不要犹豫写下自己的答案或评论这个答案/问题.

I am going to answer this myself because I could solve it more or less. If someone has additions, don't hesitate to write an own answer or comment this answer/question.

我到目前为止发现的内容:

如果您只是通过编译主要资产(assets:precompile:primary)或显式调用assets:precompile:all来使用assets:precompile,您可能最终会得到有关问题根源的提示.就我而言,我在public/tmp/上都遇到了Errno::EACCES.无法以某种方式显示出来,因此请确保您的用户具有在其中创建/删除文件和文件夹的完整权限.

If you play around with assets:precompile by e.g just compiling the primary assets (assets:precompile:primary) or explicitly calling assets:precompile:all you might end up with a hint about the source of your problem. In my case, I ran into Errno::EACCES on both public/ and tmp/. Somehow that was not displayed, so make sure your user has full rights to create/delete files and folders there.

就我而言,它有时可以工作是因为我关闭了Rails应用程序并在其关闭时对其进行了预编译.由于预编译会分配大量内存,因此我进行了一些反复试验,最终在rake尝试执行asstes:precompile:primary时得到了已知的Killed消息.该任务只是因为使用太多内存而被终止.

In my case, it worked sometimes because I've shut down the rails app and precompiled while it was down. Since precompiling allocates a lot of memory, I did some trial and error and eventually got the known Killed message when rake tries to execute asstes:precompile:primary. The task simply was killed because of using too much memory.

另一个问题是链轮无法在预编译时找到将其放入资产管道的bootstrap.将gem 'bootstrap'移到group :assets之外可以解决此问题.这也是我在使用这些命令时得到的提示.

Another problem was that sprockets could not find bootstrap to put it into the assets pipeline on precompilation. Moving gem 'bootstrap' outside of group :assets solved this. This was also something I got hinted to when I played around with the commands.

解决(或更好)的最佳方法:解决此问题是仅在本地编译资产.只需将rake assets:precompile RAILS_ENV=development放入终端,然后部署public/assets. 请记住在部署之后在开发环境中删除该文件夹,否则您将最终调试为什么在app/assets/*上所做的更改在开发中不生效.至少对我有用.

The best way to solve – or better: work around – this problem is to simply compile your assets locally. Just throw a rake assets:precompile RAILS_ENV=development into your terminal and then deploy public/assets. Remember to delete that folder in your development environment after deploying it or you will end up debugging on why your changes on app/assets/* are not taking effect in development. At least that works for me(tm).

或者,增加交换分区也可能有效.但是,在需要使用交换的VPS上进行编译可能会花费一些时间,因此我会坚持使用本地方式.

Alternatively, growing your swap partition may also work. However, compilation on a VPS where you need to use swap may take its while, so I'd stick to the local way.

这篇关于“命令失败,状态为()".预编译资产时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆