icon Capistrano 入门

第4章 capify

这章介绍部署Rails应用程序所作的准备。

下面,把你的 Rails 程序命名为 ballad
还有,用 alpha.oiax.jp 作为生产服务器的主机名称,以 /var/rails/ballad/ 作为部署目录。
Subversion 库的URL 是 https://repository.oiax.jp/svn/ballad/trunk
注意一下,这里使用的主机名称、URL等,都是虚拟的。

进入 ballad 应用程序的根目录,输入命令 capify .

% capify .
[add] writing `./Capfile'
[add] writing `./config/deploy.rb'
[done] capified!

在生成的文件中,有一个 Capfile 的内容如下,这个文件基本上不改。

load 'deploy' if respond_to?(:namespace) # cap2 differentiator
Dir['vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) }
load 'config/deploy'

config 目录中生成的 deploy.rb 文件的初始状态如下:

set :application, "set your application name here"
set :repository,  "set your repository location here"

# If you aren't deploying to /u/apps/#{application} on the target
# servers (which is the default), you can specify the actual location
# via the :deploy_to variable:
# set :deploy_to, "/var/www/#{application}"

# If you aren't using Subversion to manage your source code, specify
# your SCM below:
# set :scm, :subversion

role :app, "your app-server here"
role :web, "your web-server here"
role :db,  "your db-server here", :primary => true

更换如下。

set :application, "ballad"
set :repository,  "https://repository.oiax.jp/svn/ballad/trunk"
set :deploy_to,   "/var/rails/#{application}"

set :user, "app"
set :use_sudo, false

role :app, "alpha.oiax.jp"
role :web, "alpha.oiax.jp"
role :db,  "alpha.oiax.jp", :primary => true

通过 set :user, "app" ,将远程主机上使用 SSH 登录的用户设定为 app 。在使用其它的用户(例如rails)的情况下,将其更换。

下一行的 set :use_sudo, false ,是限定运行 Rails 应用程序时是否使用 sudo 的变量。比如我是通过 app 用户运行的,所以设定false


[修订] 2008/05/17 配合以用户 app 登录远程主机的方式,对文章进行修改。

(2008/03/27)