Upgraded to Ruby version 2.1.2, passenger still on 1.9.3

时光怂恿深爱的人放手 提交于 2021-02-07 03:06:06

问题


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,  "git@github.com: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/ruby-2.1.2@rails3.2/gems/passenger-4.0.53;
        passenger_ruby /home/myusername/.rvm/gems/ruby-2.1.2@rails3.2/wrappers/ruby;

and in my deploy.rb I explicitly tell to use the gemset ruby-2.1.2@rails3.2

set :rvm_ruby_string, "2.1.2@rails3.2"

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


回答1:


You can use multiple ruby versions managed by rvm if you use Passenger 4 or above.

Here you have some links to the guides

http://rvm.io/integration/passenger
https://www.phusionpassenger.com/documentation/Users%20guide%20Nginx.html
https://www.phusionpassenger.com/documentation/Users%20guide%20Apache.html

It looks like that to run the passenger install/upgrade in your server, you have to run rvmsudo -s first




回答2:


You should run passenger-install-nginx-module from the new RVM context to actually install the new passenger module. More info here:

https://www.phusionpassenger.com/documentation/Users%20guide%20Nginx.html#run_passenger_installer

Nginx is a different from other web servers in that it does not support loadable modules. The only way to extend Nginx is to recompile it entirely from source. Since Phusion Passenger consists of some external executables plus an Nginx module, you must recompile Nginx when first installing Phusion Passenger, but also when upgrading Nginx itself or when upgrading the Phusion Passenger version.

So, manually changing nginx config is not enough, you should run the passenger installer which should take care of setting up nginx correctly (i.e. recompiling what is necessary). I usually use apache passenger module and always run passenger installer after upgrade. Just be sure to run rvm use ruby-2.1.2@rails3.2 before running the passenger installer.



来源:https://stackoverflow.com/questions/26327062/upgraded-to-ruby-version-2-1-2-passenger-still-on-1-9-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!