Question

I'm using Capistrano to deploy multiple Rails apps to an Apache and Passenger 4 server. I'm also using the rvm-capistrano gem to install new versions of Ruby on the server.

As I understand it, the PassengerRuby line inside each VirtualHost definition specifies which Ruby and which gemset should be used for each app. When an app is upgraded from, say, Ruby 1.9.3-p374 to Ruby 1.9.3-p545, this VirtualHost definition must be changed to point to the new version of Ruby, correct?

Is there a way to get this done more automagically when Capistrano deploys the app? It might be changing the Apache config files in some way, or defining the Ruby path to indirectly point through some other config that Capistrano can change. How should this be done?

Was it helpful?

Solution

I would write a recipe to manage the Passenger config file. The basic pattern is as follows:

  1. Create an erb version of your config file, replacing dynamic variables with erb script tags to be replaced at the time the recipe is run
  2. Write a recipe that uses the erb template and uploads the resulting file to your server
  3. Call this recipe after your ruby upgrade task rvm:whatever_task_you_use_to_install_upgrade

This pattern is illustrated really nicely in this RailsCast: http://railscasts.com/episodes/337-capistrano-recipes?view=asciicast

Or, there are quite a few exmaples out there of cap recipes for installing and managing Passenger. Here's one that does not use erb, but rather inline text that gets written out to the Passenger config (see line 39): https://github.com/nesquena/cap-recipes/blob/master/lib/cap_recipes/tasks/passenger/install.rb

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top