【问题标题】:Chef deployed Puma server with a Sidekiq worker fails with incorrect ruby version errorChef 使用 Sidekiq 工作人员部署 Puma 服务器失败,并出现不正确的 ruby​​ 版本错误
【发布时间】:2015-11-08 06:22:04
【问题描述】:

这个 rails 应用程序的 puma/runit 服务一直在运行,直到我尝试通过 chef 将 Sidekiq 3.5.3 gem 部署到我的应用程序中

在我的配方中,我通过 ruby​​_build 配方安装了 2.0.0p576

which ruby  #gives me /usr/bin/ruby
/usr/bin/ruby -v #return 2.0.0p576

模板/默认/sv-myapp-run.erb

echo "$(ruby -e 'print RUBY_VERSION')" >> check_ruby.txt #returns 2.0.0
exec chpst -u root:root bundle exec puma --config config/puma.rb

在 runit 服务的日志中,我在下面收到此消息

2015-11-04_06:23:50.99541 /var/lib/gems/1.9.1/gems/sidekiq-3.5.3/lib/sidekiq.rb:3:in `<top (required)>': Sidekiq 3.5.3 does not support Ruby 1.9. (RuntimeError)

由于这不会在本地发生 - 我被引导相信这与 Chef 以及我如何在主机上设置 Ruby 有关

我还尝试安装 rvm ,清除系统 ruby​​ 并确认默认(全局和本地)为 > 2.0 - 这些都没有任何影响。

我注意到 /usr/local/bin/puma 中的声明是

#!/usr/bin/env ruby1.9.1

我将其编辑为 ruby​​ - 然后重新启动服务但没有更改。有没有办法可以强制 Puma 在 ruby​​ +>2.0 下运行?

ruby_build_ruby '2.0.0-p576'

link "/usr/bin/ruby" do
  to "/usr/local/ruby/2.0.0-p576/bin/ruby"
end



gem_package 'bundler' do
  options '--no-ri --no-rdoc'
end

include_recipe "runit"

deploy_revision("/opt/deploy") do
  revision "develop"
  repository "removed" 
  user "root"
  action :deploy
  shallow_clone true
  keep_releases 3
  rollback_on_error true  # remove release if callbacks failed
  migrate true
  migration_command "rake db:migrate"
  before_migrate do
    execute "bundle install" do
      command "bundle install"
      cwd  "#{release_path}"
      user "root" 
    end
  end
  #restart_command "rails server -b 0.0.0.0"
  # disable default behavior
  symlink_before_migrate.clear
  create_dirs_before_symlink.clear
  purge_before_symlink.clear
  symlinks.clear
end

Ubuntu 14.04,捆绑器 1.10.6

谢谢!

【问题讨论】:

    标签: ruby-on-rails chef-infra sidekiq puma


    【解决方案1】:

    我不认为您安装的 ruby​​ 是系统的默认设置(或者至少,在 Chef 执行 bundler 时不是)。我基于/var/lib/gems/1.9.1/gems/sidekiq-3.5.3 这似乎表明您已经在 1.9.1 下安装了 gem。

    我不知道您是否偏爱 rvm 或 rbenv,但每个人都有一本流行的社区食谱,可以将默认系统 ruby​​ 设置为您想要使用的,甚至只针对特定用户(因为您'正在使用 root,我会说只需将系统 ruby​​ 设置为您想要的)。

    如果您使用的是the rbenv cookbook,它将如下所示:

    include_recipe 'ruby_build'
    include_recipe 'ruby_rbenv'
    rbenv_global '2.0.0p576'
    

    您还可以省略以前使用的这些资源:

    ruby_build_ruby '2.0.0-p576'
    link "/usr/bin/ruby" do
      to "/usr/local/ruby/2.0.0-p576/bin/ruby"
    end
    

    另外,我建议以除 root 以外的其他用户身份运行,因此您只能破坏该用户的默认 ruby​​,而不是整个系统的 ruby​​。干杯!

    【讨论】:

    • 谢谢 Martin - 我花了几天时间尝试这个。最后,使用 chef 资源“gem_package”和使用 bash 资源安装 bundler 似乎有所不同——当我通过 bash 切换到 bundler 时,事情变得很好。
    猜你喜欢
    • 2014-01-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-09
    • 2020-09-23
    • 2020-05-18
    • 1970-01-01
    相关资源
    最近更新 更多