【问题标题】:Graylog2 Web Interface (Rails) using rbenv in Chef在 Chef 中使用 rbenv 的 Graylog2 Web 界面(Rails)
【发布时间】:2013-06-13 14:42:01
【问题描述】:

这很棘手,因为我使用了大约 500 个东西,但我有一个 Vagrant 盒子,它设置为处理相当于 10 个节点(不同服务器)的东西。它是一个在本地完成所有工作的机器,然后我将其拆分到生产和登台的不同服务器。

目前我无法通过 Chef 设置让 graylog2 使用 rbenv。我已经安装了 rbenv,我已经使用 rbenv shims 运行了 bundle install,并且所有 gem 都安装了。但是,实际运行的应用程序会出现这样的错误:

厨师食谱如下所示:

# Install required APT packages
package "build-essential"
package "postfix"

include_recipe "rbenv::default"
include_recipe "rbenv::ruby_build"

use_ruby_version = "1.9.3-p327"
rbenv_ruby use_ruby_version

# Install gem dependencies
%w{ bundler rake }.each do |g|
  rbenv_gem "#{g}" do
    ruby_version "#{use_ruby_version}"
  end
end

# Create the release directory
directory "#{node.graylog2.basedir}/rel" do
  mode 0755
  recursive true
end

# Download the desired version of Graylog2 web interface from GitHub
remote_file "download_web_interface" do
  path "#{node.graylog2.basedir}/rel/graylog2-web-interface-#{node.graylog2.web_interface.version}.tar.gz"
  source "https://github.com/downloads/Graylog2/graylog2-web-interface/graylog2-web-interface-#{node.graylog2.web_interface.version}.tar.gz"
  action :create_if_missing
end

# Unpack the desired version of Graylog2 web interface
execute "tar zxf graylog2-web-interface-#{node.graylog2.web_interface.version}.tar.gz" do
  cwd "#{node.graylog2.basedir}/rel"
  creates "#{node.graylog2.basedir}/rel/graylog2-web-interface-#{node.graylog2.web_interface.version}/build_date"
  action :nothing
  subscribes :run, resources(:remote_file => "download_web_interface"), :immediately
end

# Link to the desired Graylog2 web interface version
link "#{node.graylog2.basedir}/web" do
  to "#{node.graylog2.basedir}/rel/graylog2-web-interface-#{node.graylog2.web_interface.version}"
end

# Perform bundle install on the newly-installed Graylog2 web interface version
bash "bundle install" do
  cwd "#{node.graylog2.basedir}/web"
  code "rbenv local #{use_ruby_version} && source /etc/profile.d/rbenv.sh && bundle install"
  subscribes :run, resources(:link => "#{node.graylog2.basedir}/web"), :immediately
end

# Create mongoid.yml
template "#{node.graylog2.basedir}/web/config/mongoid.yml" do
  mode 0644
end

# Create general.yml
template "#{node.graylog2.basedir}/web/config/general.yml" do
  owner "nobody"
  group "nogroup"
  mode 0644
end

# Chown the Graylog2 directory to nobody/nogroup to allow web servers to serve it
execute "sudo chown -R nobody:nogroup graylog2-web-interface-#{node.graylog2.web_interface.version}" do
  cwd "#{node.graylog2.basedir}/rel"
  not_if do
    File.stat("#{node.graylog2.basedir}/rel/graylog2-web-interface-#{node.graylog2.web_interface.version}").uid == 65534
  end
  action :nothing
  subscribes :run, resources(:bash => "bundle install"), :immediately
end

# Stream message rake tasks
cron "Graylog2 send stream alarms" do
  minute node[:graylog2][:stream_alarms_cron_minute]
  action node[:graylog2][:send_stream_alarms] ? :create : :delete
  command "cd #{node[:graylog2][:basedir]}/web && RAILS_ENV=production bundle exec rake streamalarms:send"
end

cron "Graylog2 send stream subscriptions" do
  minute node[:graylog2][:stream_subscriptions_cron_minute]
  action node[:graylog2][:send_stream_subscriptions] ? :create : :delete
  command "cd #{node[:graylog2][:basedir]}/web && RAILS_ENV=production bundle exec rake subscriptions:send"
end

这与原始版本基本相同,不同之处在于它在 bash "bundle install" 厨师资源中使用了 rbenv local

所以...如果它已安装并正在运行...我怎么能让 Rails 在运行时知道所说的宝石?这甚至是屏幕截图中的问题吗?发生了什么,我该如何解决?

【问题讨论】:

    标签: ruby-on-rails chef-infra rbenv graylog2


    【解决方案1】:

    您启动 Graylog2 的方式可能没有首先正确调用 rbenv。最简单的方法是as per the rbenv wiki page,是与 binstubs 捆绑安装。所以我会改变你的捆绑安装行看起来更像:

    bundle install --deployment --binstubs

    您没有包含用于启动服务器的命令。 (您使用的是 Apache 吗?Unicorn?)如果 Unicorn 或 Thin 或其他一些您可以轻松按需启动的服务器,那么您的问题几乎解决了。只需通过 rbenv 包装器启动应用程序,它应该使用正确的 rbenv 执行:

    /path/to/my/current/bin/unicorn

    【讨论】:

    • 感谢您的回复!这是使用 Apache 和 Passenger 完成的,我实际上不知道这是如何启动的,但我会进行调查。当我在/var/graylog2/web 中执行$ which bundle 时,我得到/opt/rbenv/shims/bundle 所以我认为不需要binstubs?或者是吗?我对 rbenv 非常熟悉。
    【解决方案2】:

    我添加了以下内容:

    LoadModule passenger_module /opt/rbenv/versions/<%= node[:graylog2][:ruby_version] %>/lib/ruby/gems/1.9.1/gems/passenger-4.0.5/libout/apache2/mod_passenger.so
    PassengerRoot /opt/rbenv/versions/<%= node[:graylog2][:ruby_version] %>/lib/ruby/gems/1.9.1/gems/passenger-4.0.5
    PassengerDefaultRuby /opt/rbenv/versions/<%= node[:graylog2][:ruby_version] %>/bin/ruby
    

    我正在向 graylog2 食谱发送拉取请求,它将很快处理所有这些,并希望它被接受。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多