Aur*_*ger 5 capistrano ruby-on-rails passenger rvm rvm-capistrano
每当我使用RVM和Capistrano更新Ruby及其Gemlist时,如何更新Passenger使用的Ruby版本?检查我的应用程序是否使用正确的ruby版本和gemset的最佳方法是什么?
我有一个运行在Linode服务器(Ubuntu)上的Rails应用程序,使用NGinx和Passenger.在它运行之前没有任何问题.
以前我的应用程序使用Ruby 1.9.3-p194运行Ruby on Rails 3.2.16
我使用RVM来管理本地和服务器上的ruby版本.在我安装了Ruby-2.1.2并更新了基本的宝石(bundler,nokogiri等等)后,我为我的应用程序创建了我的新gemset.
在开发(本地)中,我使用Ruby 2.1.2,rails 3.1.19(在我升级到Rails 4之前),以及该项目的特定gemset.
我修改了我deploy.rb的Capistrano,遵循RVM-Capistrano宝石集成
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
Run Code Online (Sandbox Code Playgroud)
然后我跑了 cap deploy
我刷新了我的网页,Passenger引发了以下错误:
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
Run Code Online (Sandbox Code Playgroud)
显然,Passenger仍在运行Ruby-1.9.3而不是Ruby-2.1.2.我不确定RVM-Capistrano是否安装/更新了Ruby版本和相应的gemset.我不确定我错过了什么?
编辑:
我检查了nginx.conf作为root用户/opt/nginx/conf/nginx.conf
在我找到的文件的顶部
...
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;
}
Run Code Online (Sandbox Code Playgroud)
这是否意味着我必须使用ruby-2.1.2更改这些行?有没有办法自动化这种变化?
更新2:
我修改了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;
Run Code Online (Sandbox Code Playgroud)
并在我的deploy.rb明确告诉使用gemsetruby-2.1.2@rails3.2
set :rvm_ruby_string, "2.1.2@rails3.2"
Run Code Online (Sandbox Code Playgroud)
应用程序运行正常,Ruby解释器仍然是1.9.3.我甚至在管理页面上打印出RUBY_VERSION常量,它显示1.9.3
我不明白......
谢谢你的帮助
如果您使用 Passenger 4 或更高版本,则可以使用 rvm 管理的多个 ruby 版本。
这里有一些指南的链接
http://rvm.io/integration/passenger
https://www.phusionpassenger.com/documentation/Users%20guide%20Nginx.html
https://www.phusionpassenger.com/documentation/Users%20guide%20Apache.html
看起来要在您的服务器中运行乘客安装/升级,您必须rvmsudo -s先运行