SSH Environment for Capistrano Rails Deployment

I decided to take the plunge to capistrano 2.0 and try using my own (OS X) machine at the same time, and I was getting path errors.

First I got a 'svn: command not found' error, so I added this to my deploy file:

set :scm_command, '/opt/local/bin/svn'

That made that error go away, but then I got a 'rake: command not found' error. So I added this to my deploy file:

set :rake, '/opt/local/bin/rake'

Finally I got 'No such file to load ' rubygems' and 'custom_require.rb:27: command not found' errors, and these seemed like path problems too, so I finally decided that something was really wrong. That's when I found this post. Setting the SSH environment and 'PermitUserEnvironment yes' as described made things work!

For the record, I'm currently using Capistrano 2.0, Rails 1.2.3, and Ruby 1.8.6 to serve rails on a mongrel cluser (mongrel 1.0.1 and mongrel_cluster 1.0.2). I used MacPorts for installing ruby, mysql and apache2. Here are some of the related file contents:




load 'deploy' if respond_to?(:namespace) # cap2 differentiator
load 'config/deploy'


set :application, 'myapp'
set :user, 'myusername'
set :server_hostname, ''
set :server_home_path, '/Users/#{user}'
set :repository, 'svn+ssh://#{user}@#{server_hostname}#{server_home_path}/svn/#{application}/trunk'
set :deploy_to, '#{server_home_path}/rails/production/#{application}'
# This fixed frustrating 'sudo: no passwd entry for app' error when cap was trying
# to run the process start command as 'app' for some reason
set :runner, 'myusername'

role :app, server_hostname
role :web, server_hostname
role :db, server_hostname, :primary => true

# Not storing database.yml in svn for security purposes. Manually uploaded it as
# shared/config/database.yml.production on the server after running 'cap deploy:setup'
# and this copies it over after each code update
task :copy_database_yml, :roles => :app do
  db_config = '#{shared_path}/config/database.yml.production'
  run 'export PATH=/opt/local/bin:$PATH; gem environment; cp #{db_config} #{release_path}/config/database.yml'

after 'deploy:update_code', :copy_database_yml