How do I update the Ruby Version used by Passenger whenever I update Ruby and its Gemlist using RVM and Capistrano? What is the best way to check if my app is using the right ruby version and gemset?
I have a Rails app running on a Linode server (Ubuntu), with NGinx and Passenger. Before it was running without any problem.
Previously my app was running Ruby on Rails 3.2.16 with the Ruby 1.9.3-p194
I use RVM to manage ruby versions both locally and on the server. After I installed Ruby-2.1.2 and updated the basic gems (bundler, nokogiri, etc...) I created my new gemset for my application.
In development (locally) I use Ruby 2.1.2, rails 3.1.19 (before I upgrade to Rails 4), and a specific gemset for this project.
I modified my deploy.rb
for Capistrano, following the RVM-Capistrano gem Integration
require "rvm/capistrano"
require "bundler/capistrano"
set :user, "myusername"
set :application, "myapp"
set :deploy_to, "/home/#{user}/apps/#{application}"
set :scm, :git
set :repository, "[email protected]:myusername/#{application}.git"
set :branch, "master"
set :rvm_ruby_string, :local # use the same ruby as used locally for deployment
set :rvm_autolibs_flag, "read-only" # more info: rvm help autolibs
set :use_sudo, false
set :deploy_via, :remote_cache
set :keep_releases, 3
default_run_options[:pty] = true
set :ssh_options, { :forward_agent => true }
before 'deploy:setup', 'rvm:install_rvm' # install/update RVM
before 'deploy:setup', 'rvm:install_ruby' # install Ruby and create gemset
after "deploy:restart", "deploy:cleanup"
after "deploy", "rvm:trust_rvmrc"
namespace :deploy do
task :start do ; end
task :stop do ; end
task :restart, :roles => :app, :except => { :no_release => true } do
run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
end
# ... some more tasks for assets and symlinks
end
namespace :rvm do
task :trust_rvmrc do
run "rvm rvmrc trust #{release_path}"
end
end
I then ran cap deploy
I refreshed my webpage, and Passenger throws the following errors:
It looks like Bundler could not find a gem. Maybe you didn't install all the gems that this application needs. To install your gems, please run:
bundle install
...
Could not find rake-10.3.2 in any of the sources (Bundler::GemNotFound)
/home/myusername/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.5.3/lib/bundler/spec_set.rb:92:in `block in materialize'
...
Ruby interpreter command
/home/myusername/.rvm/gems/ruby-1.9.3-p194/wrappers/ruby
So apparently Passenger its still running Ruby-1.9.3 and not Ruby-2.1.2. I am not sure if RVM-Capistrano installed/updated the Ruby Version and the appropriate gemset. I am not sure what I missed?
EDIT:
I checked the nginx.conf
as the root user in /opt/nginx/conf/nginx.conf
At the top of the file I found
...
http {
passenger_root /home/myusername/.rvm/gems/ruby-1.9.3-p194/gems/passenger-4.0.37;
passenger_ruby /home/myusername/.rvm/gems/ruby-1.9.3-p194/wrappers/ruby;
...
server {
listen 80;
server_name XXX.XXX.XX.XX myapp.com www.myapp.com *.myapp.com;
root /home/myusername/apps/myapp/current/public;
passenger_enabled on;
client_max_body_size 4G;
}
Does that mean I have to change these lines with ruby-2.1.2? Is there a way to automate this change?
UPDATE 2:
I modified the nginx.conf
http {
passenger_root /home/myusername/.rvm/gems/[email protected]/gems/passenger-4.0.53;
passenger_ruby /home/myusername/.rvm/gems/[email protected]/wrappers/ruby;
and in my deploy.rb
I explicitly tell to use the gemset [email protected]
set :rvm_ruby_string, "[email protected]"
The app is running fine, the Ruby Interpreter is still 1.9.3. I even printed out on an admin page the RUBY_VERSION
constant, and it displays 1.9.3
I don't understand...
Thanks for your help