【问题标题】:Capistrano: Killed RAILS_ENV=production RAILS_GROUPS=assets bundle exec rake assets:precompileCapistrano:杀死 RAILS_ENV=production RAILS_GROUPS=assets bundle exec rake assets:precompile
【发布时间】:2014-08-04 07:12:44
【问题描述】:

我昨天整个下午都在处理这个问题,我发现了例如this 主题,这对我来说并不奏效。

然后我在这里找到了一个关于 SO 的主题,建议将 load 'deploy/assets' 添加到 Capfile。终于成功了!

但是今天早上当我尝试部署另一个代码时,我又遇到了这个错误:

 ** [out :: IP] bash: line 1: 15213 Killed                  RAILS_ENV=staging RAILS_GROUPS=assets bundle exec rake assets:precompile
    command finished in 38500ms
*** [deploy:update_code] rolling back

我快把我逼疯了,昨天一切都很好,但今天 - 突然之间 - 再次出现同样的错误。这是我的设置:

Capfile:

load 'deploy'
load 'config/deploy' # remove this line to skip loading any of the default tasks
load 'deploy/assets'

部署/生产.rb:

...
namespace :deploy do

  task :setup_config, roles: [:app] do
    sudo "ln -nfs #{current_path}/config/nginx.conf /etc/nginx/sites-enabled/app"
    sudo "ln -nfs #{current_path}/config/unicorn_init_production.sh /etc/init.d/unicorn_app-production"
    run "mkdir -p #{shared_path}/config"
    put File.read("config/database.yml"), "#{shared_path}/config/database.yml"
    puts "Now edit the config files in #{shared_path}."
  end
  after "deploy:setup", "deploy:setup_config"

  task :symlink_config, roles: [:app] do
    run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
  end
  after "deploy:finalize_update", "deploy:symlink_config"
  after "deploy:create_symlink", "deploy:restart"

  desc "Make sure local git is in sync with remote."
  task :check_revision, roles: [:web] do
    unless `git rev-parse HEAD` == `git rev-parse origin/master`
      puts "WARNING: HEAD is not the same as origin/master"
      puts "Run `git push` to sync changes."
      exit
    end
  end
  %w[stop].each do |command|
    desc "#{command} unicorn server"
    task command, roles: :app, except: {no_release: true} do
      run "/etc/init.d/unicorn_app-production #{command}"
    end
  end


  %w[restart].each do |command|
    desc "#{command} unicorn server"
    task command, roles: :app, except: {no_release: true} do
      run "/etc/init.d/unicorn_app-production #{command}"
    end
  end

  before "deploy", "deploy:check_revision"  
end

部署.rb:

require "capistrano/ext/multistage"
require "rvm/capistrano"
require 'bundler/capistrano'
require 'delayed/recipes' # added for running deplayed jobs

set :application, 'app'
set :bundle_flags, "--quiet --no-cache"

set :scm, :git
default_run_options[:pty] = true
set :deploy_via, :remote_cache
set :repository, 'git@bitbucket.org:name/repo.git'
set :branch, "master"
set :pty, true
set :keep_releases, 5

我会对每一个建议都非常有帮助!

谢谢大家

编辑:environments/production.rb

App::Application.configure do
  config.cache_classes = true
  config.eager_load = true

  config.consider_all_requests_local       = false
  config.action_controller.perform_caching = true
  config.serve_static_assets = true

  config.assets.js_compressor = :uglifier
  config.assets.css_compressor = :sass

  config.assets.compile = false
  config.assets.precompile = ['*.js', 'application.css', 'styles.css.scss', '*.css.erb']
  config.assets.precompile += %w(*.png *.jpg *.jpeg *.gif *.svg *.woff *.ttf *.ico)
  config.assets.digest = true
  config.assets.version = '1.2'
  config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
  config.log_level = :info
  config.i18n.fallbacks = true
  config.active_support.deprecation = :notify
  config.log_formatter = ::Logger::Formatter.new
  config.action_mailer.default_url_options = { :host => 'http://www.app.com' }
end

【问题讨论】:

  • 服务器终止进程,查看服务器上的dmesg,我认为你没有内存可以编译。
  • 你的意思是 - RAM 内存?
  • 是的, dmesg,编译的资源非常占用内存。
  • 最后两行:[5689488.101760] Out of memory: Kill process 31427 (ruby) score 184 or sacrifice child [5689488.102528] Killed process 31427 (ruby) total-vm:948244kB, anon-rss:235856kB, file-rss:0kB。到目前为止,在我有 1GB 的服务器上,我会尝试加倍。
  • 您可以在本地编译资产并移动到服务器,而无需升级内存。如果我有帮助,我可以为您发布答案吗?

标签: ruby-on-rails ruby capistrano assets production


【解决方案1】:

服务器终止进程,查看服务器上的dmesg,我认为你没有内存可以编译。 dmesg返回:

[5689488.101760] 内存不足:杀死进程 31427 (ruby) 得分 184 或 牺牲孩子 [5689488.102528] 杀死进程31427(红宝石) 总虚拟机:948244kB,anon-rss:235856kB,文件-rss:0kB

您可以在本地编译资产并移动到服务器,而无需升级内存。

看看这个gist 或这个gem

【讨论】:

  • 如果我运行 bundle exec rake assets:precompile 然后提交/推送它 + 部署它,我仍然会看到相同的错误消息:bash: line 1: 2683 Killed RAILS_ENV=production RAILS_GROUPS=assets bundle exec rake assets:precompile
  • 您应该禁用服务器上的预编译资产,尝试在Capfile 中评论load 'deploy/assets'。并在生产环境中预编译资产bundle exec rake assets:precompile RAILS_ENV=production
  • 嗯...这导致部署现在还可以,但网站上缺少一些图像(和 CSS 图标) - 评论 load 'deploy/assets' 不会是问题?
  • load 'deploy/assets' 它只是资产编译的钩子,显示production.rb 以及您使用的代理服务器nginxapache
  • 更新了关于 production.rb 的原始问题。我正在使用nginx
猜你喜欢
  • 2019-10-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-05-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多