Problem: Apache/Passenger don't recognize RVM
I have a multi-user install of RVM, per the canonical instructions: http://beginrescueend.com/rvm/install/
I then edited /etc/profile.d/rvm.sh to include the following line so that Ruby 1.9 is the version used for all users logged in:
rvm use --default 1.9.2
I have at least 3 users on my system:
- ubuntu (the default user I use to perform all interactive tasks)
- passenger (this is the user for deploy tasks)
- www-data (this is presumably the user I set up to serve httpd requests)
When logged in interactively to ubuntu and passenger, the following returns correctly:
$ ruby -v
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-linux]
However, the www-data user, which actually serves these requests, never executes /etc/profile.d/rvm.sh (or anything in profile.d, for that matter). As a result, the following always happens when logged in as the www-data user:
$ ruby -v
ruby 1.8.7 (2010-08-16 patchlevel 302) [x86_64-linux]
As a result of this, Bundler runs just fine on my development sandbox with the right Ruby version, but craps out with a "Could not install Gem on Ruby 1.8" type of error when running:
$ cap deploy
<snip>
* executing "cd /var/www/app/releases/20111031001406 && bundle install --gemfile /var/www/app/releases/20111031001406/Gemfile --path /var/www/app/shared/bundle --deployment --quiet --without development test"
servers: ["example.com"]
[example.com] executing command
</snip>
(example.com and app are placeholders for my real server and application)
The error I receive is to the tune of "The linecache gem requires Ruby > 1.9)" which is how I know that Ruby 1.9.2 not running is the problem.
How do I get Apache to recognize RVM and the Ruby version I want? (RVM and the Ruby I want are installed, per the multi-user pattern, within /usr/local/rvm
I have followed every instruction I can think of many times over, but I'm clearly missing something here. Any guidance here would be deeply appreciated.
FWIW, this is my Capistrano deploy script:
# if you're still using the script/reapear helper you will need
# # these http://github.com/rails/irs_process_scripts
#
# # bundler bootstrap
require 'bundler/capistrano'
set :nice_name, "App"
set :application, "app"
set :domain, "example.com"
role :web, "#{domain}" # Your HTTP server, Apache/etc
role :app, "#{domain}" # This may be the same as your `Web` server
role :db, "#{domain}", :primary => true # This is where Rails migrations will run
# # server details
set :default_run_options, {:pty => true}
set :ssh_options, {:forward_agent => true, :keys => "/path_to/ssh.key"}
#ssh_options[:keys] = [File.join(ENV["HOME"], ".ssh", "id_rsa")]
set :deploy_to, "/var/www/#{application}/"
set :user, "passenger"
set :use_sudo, false
# repo details
set :scm, :git
set :scm_username, "githubuser"
set :repository, "git://github.com/githubuser/app.git"
set :branch, "master"
set :git_enable_submodules, 1
# tasks
namespace :deploy do
task :start, :roles => :app do
run "touch #{current_release}/tmp/restart.txt"
end
task :stop, :roles => :app do
# Do nothing.
end
desc "Restart Application"
task :restart, :roles => :app do
run "touch #{current_release}/tmp/restart.txt"
end
desc "Symlink shared resources on each release - not used"
task :symlink_shared, :roles => :app do
#run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
end
end
namespace :passenger do
desc "Restart Application"
task :restart do
run "touch #{current_path}/tmp/restart.txt"
end
end
after :deploy, "passenger:restart"
after 'deploy:update_code', 'deploy:symlink_shared'