【问题标题】:Capistrano killing assets:precompileCapistrano 杀死资产:预编译
【发布时间】:2013-02-23 01:12:05
【问题描述】:

我正在尝试部署我的应用程序,但我不断收到

*** [err :: xxx.xxx.xx.xxx] bash: line 1:  9953 Killed                  bundle exec rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile

我认为问题在于该过程花费的时间太长。日志中没有错误,top 没有显示任何异常。我确实设法摆脱日志的是,它正在杀死的进程似乎是 application.js 编译。

当我在本地运行 rake assets:precompile 时,没有错误/警告。

我可以延长 capistrano 在终止进程之前等待的长度吗?这真的是问题吗?我还能去哪里看?

更新

运行时

bundle exec rake assets:precompile RAILS_ENV=production RAILS_GROUPS=assets --trace

我得到以下输出

** Invoke assets:precompile (first_time)
** Execute assets:precompile
** 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 tmp:cache:clear (first_time)
** Execute tmp:cache:clear
** Execute assets:precompile:primary
Killed

当我跑步时

bundle exec rake assets:precompile RAILS_ENV=production --trace

我明白了

** 执行资产:预编译

.../.rvm/rubies/ruby-1.9.3-p374/bin/ruby path/to/app/production/shared/bundle/ruby/1.9.1/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 tmp:cache:clear (first_time)

** Execute tmp:cache:clear

** Execute assets:precompile:primary

rake aborted!

Command failed with status (): [/home/user/.rvm/rubies/ruby-1.9.3-p374...]

path/to/app/production/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/file_utils.rb:53:in `block in create_shell_runner'

path/to/app/production/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/file_utils.rb:45:in `call'

path/to/app/production/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/file_utils.rb:45:in `sh'

path/to/app/production/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/file_utils_ext.rb:40:in `sh'

path/to/app/production/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/file_utils.rb:80:in `ruby'

path/to/app/production/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/file_utils_ext.rb:40:in `ruby'

path/to/app/production/shared/bundle/ruby/1.9.1/gems/actionpack-3.2.11/lib/sprockets/assets.rake:12:in `ruby_rake_task'

path/to/app/production/shared/bundle/ruby/1.9.1/gems/actionpack-3.2.11/lib/sprockets/assets.rake:21:in `invoke_or_reboot_rake_task'

path/to/app/production/shared/bundle/ruby/1.9.1/gems/actionpack-3.2.11/lib/sprockets/assets.rake:29:in `block (2 levels) in <top (required)>'

path/to/app/production/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/task.rb:228:in `call'

path/to/app/production/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/task.rb:228:in `block in execute'

path/to/app/production/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/task.rb:223:in `each'

path/to/app/production/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/task.rb:223:in `execute'

path/to/app/production/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/task.rb:166:in `block in invoke_with_call_chain'

/home/user/.rvm/rubies/ruby-1.9.3-p374/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'

path/to/app/production/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/task.rb:159:in `invoke_with_call_chain'

path/to/app/production/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/task.rb:152:in `invoke'

path/to/app/production/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:143:in `invoke_task'

path/to/app/production/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:101:in `block (2 levels) in top_level'

path/to/app/production/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:101:in `each'

path/to/app/production/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:101:in `block in top_level'

path/to/app/production/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:110:in `run_with_threads'

path/to/app/production/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:95:in `top_level'

path/to/app/production/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:73:in `block in run'

path/to/app/production/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:160:in `standard_exception_handling'

path/to/app/production/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/lib/rake/application.rb:70:in `run'

path/to/app/production/shared/bundle/ruby/1.9.1/gems/rake-10.0.3/bin/rake:33:in `<top (required)>'

path/to/app/production/shared/bundle/ruby/1.9.1/bin/rake:23:in `load'

path/to/app/production/shared/bundle/ruby/1.9.1/bin/rake:23:in `<main>'

Tasks: TOP => assets:precompile

这不会发生在暂存目录中。我觉得它在盯着我的脸

【问题讨论】:

  • 直接在服务器上运行相同的命令会发生什么?还是当您说“本地”时,您的意思是?
  • 顺便说一句。我假设您在 Capfile 中使用默认的 load 'deploy/assets' 调用?
  • 我在我的 capfile 中使用 load 'deploy/assets' 调用并在我们的一台 linux 服务器上收到此错误

标签: ruby-on-rails ruby-on-rails-3 capistrano


【解决方案1】:

所以我认为我们的问题是 bootstrap-sass 是资产预编译的一部分。所以它炸毁了所有的css,然后把它全部编译下来。当这与大量 sass/css 结合使用时,该进程会使用大量内存,而操作系统会杀死它。经过大量研究,我遇到了一个相当不错的解决方案。在本地编译、压缩、上传、在服务器上解压、在服务器上符号链接,然后删除所有创建的额外文件(本地资产/压缩文件)。

这是脚本

namespace :deploy do
  namespace :assets do

    task :precompile, :roles => :web do
      from = source.next_revision(current_revision)
      if capture("cd #{latest_release} && #{source.local.log(from)} vendor/assets/ lib/assets/ app/assets/ | wc -l").to_i > 0
        run_locally("RAILS_ENV=#{rails_env} rake assets:clean && RAILS_ENV=#{rails_env} rake assets:precompile")
        run_locally "cd public && tar -jcf assets.tar.bz2 assets"
        top.upload "public/assets.tar.bz2", "#{shared_path}", :via => :scp
        run "cd #{shared_path} && tar -jxf assets.tar.bz2 && rm assets.tar.bz2"
        run_locally "rm public/assets.tar.bz2"
        run_locally("rake assets:clean")
      else
        logger.info "Skipping asset precompilation because there were no asset changes"
      end
    end

    task :symlink, roles: :web do
      run ("rm -rf #{latest_release}/public/assets &&
            mkdir -p #{latest_release}/public &&
            mkdir -p #{shared_path}/assets &&
            ln -s #{shared_path}/assets #{latest_release}/public/assets")
    end
  end

  # other stuff...

end

这里是where I found the script。它提供了更好的解释

编辑

较新的 Rails 部署存在问题。我不确定确切的版本,但它似乎会影响 rails 4。资产需要指定它们正在编译的环境,否则生产/登台环境将找不到它们。

【讨论】:

  • 您提到的这背后的问题是 RAM + bootstrap 不足。由于我只是在我们的一个测试服务器上遇到了这个问题,我只是将该服务器移至开发模式,因为我宁愿使用 capistrano 编译服务器上的资产。我没有尝试您的答案,但我假设它有效,并且可能是有用的解决方法。感谢您发布此内容,我 +50 回答了这个问题。
  • 感谢 Peter,这个脚本很有魅力,将我的部署时间从几分钟缩短到几秒钟。
  • @ArtemKalinchuk 什么不起作用?你遇到了什么错误?你发了 SO 帖子吗?
  • 哪个链接?原始脚本的链接似乎对我有用
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-07-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-02-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多