【问题标题】:RVM + Nginx + Passenger in ChefRVM + Nginx + Chef 中的乘客
【发布时间】:2014-04-09 11:45:41
【问题描述】:

我正在尝试使用适用于 nginx 的社区食谱和适用于 RVM 的 fnichol's 在 Chef 的 RVM 上设置 Nginx 和乘客。一切都在 ubuntu 上。

现在,我的问题是,如果我使用 Knife ec2 引导机器并尝试一次性安装所有内容,它会失败。

在大多数情况下,它运行良好,很好地拾取 RVM 和乘客,直到它意识到乘客没有编译,尝试使用默认 ruby​​ 1.9.1 中的 rake 并失败。

如果我然后连接到机器并运行sudo chef-client,一切都会完美地完成并且我已经正确配置了机器。为什么它在第一次运行时不起作用? 第一次运行时我缺少什么设置/路径元素/环境变量?

我的食谱很简单:

include_recipe "chef_gem"
include_recipe "rvm::system"
include_recipe "rvm::gem_package"

group "rvm" do
  action :modify
  members "ubuntu"
  append true
end

include_recipe "nginx::source"

我的属性少了一点:

# rvm                                                                                                                                                                                                                                                                         
normal['rvm']['rubies'] = ['2.1.0']
normal['rvm']['default_ruby'] = node['rvm']['rubies'].first
normal['rvm']['user_default_ruby'] = node['rvm']['rubies'].first
normal['rvm']['gems'][node['rvm']['default_ruby']] = [{name: "bundler"}, {name: "rake"}]

# nginx                                                                                                                                                                                                                                                                       
normal['nginx']['version'] = '1.4.5'
normal['nginx']['dir'] = '/etc/nginx'
normal['nginx']['log_dir'] = '/var/log/nginx'
normal['nginx']['binary'] = "/opt/nginx-#{node['nginx']['version']}/sbin"
normal['nginx']['source']['sbin_path'] = "#{node['nginx']['binary']}/nginx"
normal['nginx']['init_style'] = 'init'
normal['nginx']['default_site_enabled'] = false
normal['nginx']['source']['version'] = node['nginx']['version']
normal['nginx']['source']['modules'] = ["nginx::http_stub_status_module",
                                        "nginx::http_ssl_module",
                                        "nginx::http_gzip_static_module",
                                        "nginx::passenger"]
normal['nginx']['source']['prefix'] = "/opt/nginx-#{node['nginx']['source']['version']}"
normal['nginx']['source']['default_configure_flags'] = ["--prefix=#{node['nginx']['source']['prefix']}",
                                                        "--conf-path=#{node['nginx']['dir']}/nginx.conf",
                                                        "--sbin-path=#{node['nginx']['source']['sbin_path']}"]
normal['nginx']['source']['url'] = "http://nginx.org/download/nginx-#{node['nginx']['source']['version']}.tar.gz"

# passenger                                                                                                                                                                                                                                                                   
normal['nginx']['passenger']['version'] = '4.0.37'
normal['nginx']['passenger']['ruby'] = "#{node['rvm']['root_path']}/wrappers/ruby-#{node['rvm']['default_ruby']}/ruby"
normal['nginx']['passenger']['gem_binary'] = "#{node['rvm']['root_path']}/wrappers/ruby-#{node['rvm']['default_ruby']}/gem"
normal['nginx']['passenger']['root'] = "#{node['rvm']['root_path']}/gems/ruby-#{node['rvm']['default_ruby']}/gems/passenger-#{node['nginx']['passenger']['version']}"
normal['nginx']['configure_flags'] = ["--add-module=#{node['rvm']['root_path']}/gems/ruby-#{node['rvm']['default_ruby']}/gems/passenger-#{node['nginx']['passenger']['version']}/ext/nginx"]

有问题的部分:

*** The Phusion Passenger support files are not yet compiled. Compiling them for you... ***
*** Running 'rake nginx CACHING=false' in /usr/local/rvm/gems/ruby-2.1.0/gems/passenger-4.0.37/ext/nginx... ***
STDERR: /usr/lib/ruby/1.9.1/rubygems/dependency.rb:247:in `to_specs': Could not find rake (>= 0) amongst [] (Gem::LoadError)
    from /usr/lib/ruby/1.9.1/rubygems/dependency.rb:256:in `to_spec'
    from /usr/lib/ruby/1.9.1/rubygems.rb:1231:in `gem'
    from /opt/chef/embedded/bin/rake:22:in `<main>'
---- End output of "bash"  "/tmp/chef-script20140306-1255-1fqdatt" ----
Ran "bash"  "/tmp/chef-script20140306-1255-1fqdatt" returned 1
[2014-03-06T11:42:13+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)

导致上面的命令是:

cd nginx-1.4.5 && ./configure --prefix=/opt/nginx-1.4.5 --conf-path=/etc/nginx/nginx.conf --sbin-path=/opt/nginx-1.4.5/sbin/nginx --add-module=/usr/local/rvm/gems/ruby-2.1.0/gems/passenger-4.0.37/ext/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module && make && make install`

我找到了许多使用Passenger 和RVM 配置Nginx 的指南,但没有一个是完整的。 请帮忙

【问题讨论】:

    标签: nginx rvm passenger chef-infra


    【解决方案1】:

    好的,所以我要回答我自己的问题。

    系统范围安装中的 RVM 会创建一个文件 /etc/profile.d/rvm.sh,该文件设置(以及其他)PATH 变量。此文件在第一次运行期间未加载,因此我的 PATH 变量不包含 RVM 文件夹。

    我在食谱中添加了以下内容:

    ENV['PATH']="#{node['audioguide']['rvm_path']}:#{ENV['PATH']}"
    

    到属性文件:

    default['audioguide']['rvm_path'] = "#{node['rvm']['root_path']}/gems/ruby-#{node['rvm']['default_ruby']}/bin:#{node['rvm']['root_path']}/gems/ruby-#{node['rvm']['default_ruby']}@global/bin:#{node['rvm']['root_path']}/rubies/ruby-#{node['rvm']['default_ruby']}/bin"
    

    这样我的 RVM 路径可以立即使用。


    顺便说一句,我将探索在未来部署中使用ruby-build 代替rvm 的可能性。 RVM 是一个很棒的工具,但可能应该保留在开发环境中,而不是生产服务器上。


    编辑:我的 PATH 仍然存在一些问题,所以我后来将 ENV['PATH'] 替换为 magic_shell_environment

    magic_shell_environment 'PATH' do
      value "#{node[cookbook_name]['rvm_path']}:#{ENV['PATH']}"
    end
    

    整个食谱是here

    【讨论】:

    • 我喜欢你使用属性设置的方式,我刚开始的方式和你一样,它为我提供了很好的指导 - 所以谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-31
    • 2011-02-28
    • 1970-01-01
    相关资源
    最近更新 更多