开发者

Switch ruby when restarting rails app deployed on Passenger

Is it possible to switch from Ruby 1.8.7 to 1.9.2 when restarting a Rails app that is deployed on Passenger? It should be possible to change PassengerRuby in httpd.conf and restarting Apache. I want to know how it can be done without restarting Apache every time.

More info: We have two different apps, one on Rails 2.3.8 and one on 3.0.5 with the same name, and want to switch 开发者_如何学Cbetween them for testing purposes.

Thanks.


Yes you can switch which versions of ruby you use. Life is easy when you use rvm (http://rvm.beginrescueend.com/). Then you can install the passenger gem in different ruby environments, and when you do it in each environment, the passenger-install-apache2-module command will tell you what to put in the apache config file. For example, mine is now (mac osx - should be similar in other *nixes):

### system ruby and passenger
#LoadModule passenger_module /Library/Ruby/Gems/1.8/gems/passenger-3.0.7/ext/apache2/mod_passenger.so
#PassengerRoot /Library/Ruby/Gems/1.8/gems/passenger-3.0.7
#PassengerRuby /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby

### rvm gemset 1.8.7@rails2.3.11 ruby and passenger
LoadModule passenger_module /Users/matt/.rvm/gems/ruby-1.8.7-p334@rails2.3.11/gems/passenger-3.0.7/ext/apache2/mod_passenger.so
PassengerRoot /Users/matt/.rvm/gems/ruby-1.8.7-p334@rails2.3.11/gems/passenger-3.0.7
PassengerRuby /Users/matt/.rvm/wrappers/ruby-1.8.7-p334@rails2.3.11/ruby

I can comment/uncomment the appropriate one and restart apache with the different version of ruby. This also works for ruby 1.9.2 and ruby enterprise edition too.


You don't need a recompile. You just just need to change the PassengerRuby option in the web server. You do need to restart the web server however, just touching restart.txt is not enough.

You can also use Passenger Standalone as a replacement for the Thin/Mongrel/Unicorn reverse proxy setup that bioneuralnet has mentioned. In fact we have a blog post dedicated to running multiple Ruby versions with Passenger Standalone: http://blog.phusion.nl/2010/09/21/phusion-passenger-running-multiple-ruby-versions/


Since Passenger kind of "embeds" itself into Apache, I don't it's possible to switch ruby interpreters without a restart (and possibly even a recompile of Passenger?). To achieve that level of flexibility you may need to look into some kind of reverse-proxy setup involving a stand-alone app server like Thin, Unicorn or Mongrel, running behind Apache or Nginx.

If that's out of the question, then it is strictly possible for Rails 2.3.8 and 3.0.5 apps to both run on Ruby 1.8.7. I have several Rails 3 apps deployed on 1.8.7, though hopefully that will change soon. Assuming your 3.0.5 app doesn't have explicit 1.9 dependencies, why can't you just run them both side by side on 1.8 in separate virtual hosts?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜