This is tricky as I'm using about 500 things, but I have a Vagrant box which is set up to handle what equates to 10 nodes (different servers). It's one box which locally does everything, then I split it up to different servers in production and staging.
Currently I cannot get graylog2 to use rbenv via the Chef setup. I have rbenv installed, I have bundle install running using the rbenv shims and the gems are all installed. But, the actual running application is erroring like this:
The chef recipe looks like this:
# 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
This is mostly the same as the original with the difference that it uses rbenv local in the bash "bundle install" chef resource.
So... if it's intalled, and running... how the heck do I make Rails know about said gems when it runs? Is that even the problem in the screenshot? What is happening and how do I fix it?
It's likely that the way you're starting Graylog2 doesn't properly invoke rbenv first. The easiest way to do that, as per the rbenv wiki page, is to bundle install with binstubs. So I'd change your bundle install line to look more like:
bundle install --deployment --binstubs
You didn't include the command you use to start your server. (Are you using Apache? Unicorn?) If Unicorn or Thin or some other server you can easily start on demand, your problems are nearly solved. Simply start the app through the rbenv wrapper and it should execute with the proper rbenv:
/path/to/my/current/bin/unicorn
I added the following:
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
I'm sending in a pull request to the graylog2 cookbook which will take care of all of this soon, and hopefully it gets accepted.
Related
I'm deploying a Rails app with Mina mina:deploy which clones from a git repo and Bundler installs the gems.
# /config/deploy.rb
# ...
task :deploy => :environment do
deploy do
invoke :'git:clone'
invoke :'bundle:install'
# ...
end
end
However, unlike when I bundle install manually, mina is installing each gem anew. With a healthy number of gems, this takes roughly 10 minutes to complete. How can I deploy while pointing bundler to use any locally available (already installed) gems where possible?
I've also tried replacing invoke :'bundle:install' with queue! "bundle install --local" with no change in behavior.
For that you need to use a local copy of the gems that you have without checking rubygems so after installing gems you run bundle package to create a cache of the gems used and instead of running bundle install you should run bundle install --local to use only the cached copy of gems without checking the rubygems.com .
I am trying to deploy rails app through chef . code deployed successfully ,but bundle install throwing error for specific gems , When installed manually gem installs without any issues , as per the chef error i got to know that , to execute bundle install chef uses its embedded ruby version and path for the same , but system is installed with ruby 2.0 using rvm .Can we override the chef ruby path to system ruby path ? I am using following code to deploy ,
deploy_branch "master" do
repo repo_url
migrate false
action :deploy
branch 'master'
enable_submodules true
before_migrate do
current_release_directory = release_path
running_deploy_user = new_resource.user
bundler_depot = new_resource.shared_path + '/bundle'
excluded_groups = %w(development test)
script 'Bundling the gems' do
interpreter 'bash'
cwd current_release_directory
user running_deploy_user
code <<-EOS
bundle install --quiet --deployment --path #{bundler_depot} \
--without #{excluded_groups.join(' ')}
EOS
end
end
end
I am using CentOS. Here is my output:
# which rvm
/usr/local/rvm/bin/rvm
# rvm ruby-1.9.3-p392#gemset
# /usr/local/rvm/bin/rvm ruby-1.9.3-p392#gemset
RVM is not a function, selecting rubies with 'rvm use ...' will not work.
You need to change your terminal emulator preferences to allow login shell.
Sometimes it is required to use `/bin/bash --login` as the command.
Please visit https://rvm.io/integration/gnome-terminal/ for a example.
As you can see if I am using just rvm everything is working. But capistrano using full path in commands like this
[46f28bd9] Command: cd /var/www/app/releases/20140718172057 && /usr/local/rvm/bin/rvm ruby-1.9.3-p392#gemset do bundle install --binstubs /var/www/app/shared/bin --path /var/www/app/shared/bundle --without development test --deployment --verbose
So it just fails and all gems being installed on default ruby instead of ruby-1.9.3-p392#gemset
Thanks for any suggestions.
My assumptions:
you are using Capistrano v3
have already included require 'capistrano/rvm' in your Capfile
when you cd into your project directory you have something like .ruby-version and .ruby-gemset setting up RVM for you.
You might want to try something like this
within fetch(:current_path) do
with rails_env: fetch(:rails_env) do
execute :bundle, "install"
end
end
The way Tasks work in v3 is different: https://github.com/capistrano/capistrano#tasks
tl;dr: execute(:bundle, :install) and execute('bundle install') don't behave identically!
I have installed sphinx and have done all necessary changes followed this steps
wget http://www.sphinxsearch.com/downloads/sphinx-0.9.9.tar.gz
tar -xzf sphinx-0.9.9.tar.gz
After that, we should compile Sphinx from the source:
cd sphinx-0.9.9-rc2/
./configure
sudo make
sudo make install
In Rails 3, open Gemfile in the root directory and add the line below:
gem 'thinking-sphinx', :git => 'http://github.com/freelancing-god/thinking-sph
And run the following command:
bundle install
Thinking Sphinx gem adds a few rake tasks to your application. The most important ones:
rake thinking_sphinx:index – Create the index
rake thinking_sphinx:reindex – Reindex Sphinx without regenerating the configuration file
rake thinking_sphinx:start – Start up Sphinx's daemon
rake thinking_sphinx:stop – Shut down the daemon
but getting error FATAL: no indexes found in config file '/home/gvo/dcms/config/development.sphinx.conf'
but when i run same with RAILS_ENV= production it works fine. Any suggestion or help would be really great.
Yeah, those names are confusing. You need to make sure the ThinkingSphinx configuration in app/config/sphinx.yml (paths, what to index) is available to the TS gem for your environment. TS uses this config to generate the configuration used by the underlying Sphinx server. You may have to create needed directories for the indexer to be able to write index files, logs, and a few other things. It's likely that the config for development is different than production.
My custom capistrano task "app:sample" fails with the following error message:
mnylen ilmo-on-rails $ cap app:sample
* executing `app:sample'
* executing "export RAILS_ENV=production; cd /home/mnylen/ilmo-on-rails/current; ruby script/coursegen 10"
servers: ["rails.cs.helsinki.fi"]
* establishing connection to gateway `melkinpaasi.cs.helsinki.fi'
* Creating gateway using melkinpaasi.cs.helsinki.fi
* establishing connection to `rails.cs.helsinki.fi' via gateway
Password:
[rails.cs.helsinki.fi] executing command
*** [err :: rails.cs.helsinki.fi] Rails requires RubyGems >= 1.3.2. Please install RubyGems and try again: http://rubygems.rubyforge.org
command finished
failed: "sh -c 'export RAILS_ENV=production; cd /home/mnylen/ilmo-on-rails/current; ruby script/coursegen 10'" on rails.cs.helsinki.fi
Am I missing something or doing something wrong? The task is:
namespace :app do
desc "Run sample data on production2
task :sample do
run "export RAILS_ENV=production; cd #{current_path}; ruby script/coursegen 10"
end
end
If I run the same command from the actual server, it works fine.
Cap is running the remote command as an unexpected user - and that user does not have the correct path to ruby and gem. Check your settings in your recipe for :user and :use_sudo. Carefully read the cap output to see what user is being connected. I see you are using a :gateway; there can be two users in this case. One to connect to the gateway, and another to actually run commands on the target server.
Okay, solved.
The problem was that there was two Ruby installations on the production server.
The .profile file under my home directory on the production server set the PATH environment variable to point to the correct Ruby version.
run command, it seems, doesn't source the .profile file and thus, running ruby script/coursegen 10 in the task used the wrong Ruby version, which was the reason for the weird error message about RubyGems version. This also explains why it worked when manually running the command from production servers shell.
My solution was to use full path to the Ruby executable in my run task, like this:
run "export RAILS_ENV=production; cd #{current_path}; /opt/ruby-enterprise-1.8.7-2009.10/bin/ruby script/coursegen 10"
Of course, this isn't pretty, but it works. If anyone has any prettier solutions, I'd be more than glad to use those instead. :)
Seems like you should update your RubyGems on the remote server.