如何为Capistrano指定单独的应用程序和数据库服务器?

时间:2009-07-20 19:15:19

标签: ruby-on-rails ruby deployment capistrano

我正在尝试将Rails应用程序部署到运行Passenger的CentOS服务器。 SVN存储库和MySQL数据库分别托管在不同的机器上。 (换句话说,总共涉及三个独立的主机。)

这是我的deploy.rb文件(取自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似乎成功了。至少没有错误。但是cap deploy失败了。有很多输出,但结果似乎是Capistrano试图将我的应用部署到我为:db指定的“角色” - 尝试将应用部署到数据库主机。

    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

1 个答案:

答案 0 :(得分:4)

如果您不需要数据库框中的Rails代码,这是一个简单的修复 - 不要定义:db角色。

默认情况下,

cap deploy会将代码放在您定义的所有角色的所有框中。