views:

144

answers:

1

I'm trying to deploy a Rails app to a CentOS server running Passenger. The SVN repository and MySQL database are each hosted on separate machines. (In other words, there's a total of three separate hosts involved.)

Here is my deploy.rb file (taken from the Passenger docs):

set :application, 'myapp'
set :repository,  'svn+ssh://user@svn_host.com/var/svn/myapp/trunk'

# Changed this to true because I do in fact use sudo.
set :use_sudo,    true

set :deploy_to,   "/opt/deployed_rails_apps/#{application}"

role :app, 'user@app_host.com'
role :web, 'user@app_host.com'

# Originally this had a "primary => true" option, but cap deploy:setup failed
# when that option was present.
role :db,  'user@db_host.com'    

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
end

cap deploy:setup seems to succeed. At least there are no errors. But cap deploy fails. There's a lot of output, but the upshot appears to be that Capistrano is trying to deploy my app to the "role" I specified for :db -- trying to deploy the app to the DB host.

    servers: ["app_host.com", "db_host.com"]

...

 ** [db_host :: out] Permission denied, please try again.
 ** [db_host :: out] user@svn_host.com's password:

...

failed: "sh -c 'svn checkout -q  -r184 svn+ssh://user@svn_host.com/var/svn/myapp/trunk /opt/deployed_rails_apps/myapp/releases/20090720190553 && (echo 184 > /opt/deployed_rails_apps/myapp/releases/20090720190553/REVISION)'" on user@db_host.com
+3  A: 

If you don't need your Rails code on the db box, it's an easy fix - don't define a :db role.

cap deploy by default puts the code on all the boxes in all the roles you've defined.

Sarah Mei
Thanks. So why is that ":db" role included in so many examples? Under what circumstances would I want to have app code on the DB box?
Ethan
Most commonly, you want to run rake tasks on that machine.
Sarah Mei