Vlad the Deployer 配合 mod_rails 使用的文档

作者: wosmvp /wosmvp@gmail.com
php?name=%C8%D5%C6%DA" onclick="tagshow(event)" class="t_tag">日期: 2008/7/2
发表于:http://www.ruby-lang.org.cn

Vlad the Deployer 一个简单的自动部署Rails的工具,号称Capistrano十分之一的复杂度……

难道这不是我们学习的理由吗? 代码相当短,有问题还可以轻松的 hack 一下
1. 测试环境:
   1. Web服务器的URL: DreamHost提供
     ruby 1.8.5
     rails 2.1
     svn版本:1.4.2
   2. SVN服务器的URL: Google Code提供
   3. 测试机环境:
     系统:Ubuntu-7.10-amd64
     svn版本:1.4.4
     Vlad the Deployer版本号: 自编译版 1.2.0.1 (2008/7/1日取源码)

2. 使用方法:
   1) 安装Vlad the Deployer
      下载 Vlad the Deployer 源码
      git clone git://github.com/aussiegeek/vlad.git
      打包代码为gem文件
            gem build vlad.gemspec 
        安装 Vlad the Deployer
            gem install vlad-1.2.0.1.gem -l

   2) 添加mod_rails支持
     在Rakefile中添加
      require 'vlad'
      Vlad.load :app => 'passenger'

   3) 修改配置
      配置文件为config/deploy.rb ,一个基本可以运行的deploy.rb修改
      set :domain,  "用户名@WEB服务器"
      set :deploy_to, "在WEB服务器上的位置,如 /home/username/web "
      set :repository, "SVN服务器"

      本例中使用的deploy.rb:
      set :svn_cmd, "svn --username 用户名 --password 密码"
      set :domain,  "***@www.***.com"
      set :deploy_to, "程序位置"
      set :repository, "Google svn地址"
   4) 服务器端配置:
      略


   5) 包含的Rake任务:
      rake vlad:cleanup  # Clean up old releases.
      rake vlad:debug  # Show the vlad setup.
      rake vlad:invoke  # Invoke a single command on every remote server.
      rake vlad:migrate  # Run the migrate rake task for the the app.
      rake vlad:rollback # Rolls back to a previous version and restarts.
      rake vlad:setup  # Setup your servers.
      rake vlad:setup_app # Prepares application servers for deployment.
      rake vlad:start  # (Re)Start the web and app servers
      rake vlad:start_app # Restart PassengerVlad.load :app => 'passenger'
      rake vlad:start_web # (Re)Start the web servers
      rake vlad:stop   # Stop the web and app servers
      rake vlad:stop_web # Stop the web servers
      rake vlad:update  # Updates your application server to the latest revision.

   例如:
        rake vlad:update vlad:migrate vlad:start_app
     该命令代表的含义为更新后,再进行migrate ,然后重新启动WEB服务器


3. 其它注意事项:
   1) 使用其它版本管理工具,例如git,需修改Rakefile
      require 'vlad'
      Vlad.load :scm => :git

   2) SVN需要用户名,密码
      在deploy.rb中设定Vlad the Deployer
      set :svn_cmd, "svn --username 用户名 --password 密码"

   3) 简化命令的使用
   vlad采用的是Rake命令,可进行如下简化等:
      rake vlad:update vlad:migrate vlad:start_app 
      修改为
      task 'easyupdate'=> ['vlad:update', 'vlad:migrate','vlad:start_app']

      然后可以通过
            rake easyupdate
        来执行
            rake vlad:update vlad:migrate vlad:start_app
        命令
        
   4) 以下为所有可以设定的系统变量
      == Core Variables

      repository::    REQUIRED: Repository path: e.g. http://repo.example.com/svn
      deploy_to::    REQUIRED: Deploy path on target machines. e.g. /var/www/app
      domain::     REQUIRED: Used for the common case of a single target
             server. e.g. example.com
      current_path::   The full path on the remote host that will be symlinked
             as 'current'. Defaults to "#{deploy_to}/current".
      current_release::  The full path to the current release's actual location.
             Defaults to "#{releases_path}/#{releases.last}".
      deploy_timestamped:: Create timestamped release directories instead of using
             revision numbers. Defaults to true.
      deploy_via::    Which SCM command should be used when deploying the app.
             Defaults to "export".
      latest_release::   The most recent release, which may not yet have been
             symlinked. Defaults to release_path.
      migrate_args::   Set this to change the RAILS_ENV that 'rake db:migrate'
             will run under. Defaults to "".
      migrate_target::   Set this if you need to specify a particular migration
             'VERSION' number. Defaults to "latest".
      rails_env::    Specifies the RAILS_ENV environment variable that will
             be used. Defaults to "production".
      rake::      Set this if you need to specify an alternate path to
             'rake'. Defaults to "rake".
      release_name::   Name of the release directory, if deploy_timestamped is
             true. Defaults to timestamp: "YYYYMMDDHHMMSS".
      release_path::   Path to this release, which may not have been created
             yet. Defaults to "#{releases_path}/#{release_name}".
      releases::     An array of all existing releases, oldest first.
             Defaults to latest release directory name.
      releases_path::   Full path to the 'releases' directory on the remote host.
             Defaults to "#{deploy_to}/releases".
      revision::     Revision to use for release. Defaults to 'head'.
      rsync_cmd::    Path to rsync command. Defaults to "rsync".
      rsync_flags::    Flags for rsync. Defaults to ['-azP', '--delete'].
      scm_path::     Path on the remote host that will be used as 'working
             space' for SCM tasks. Defaults to "#{deploy_to}/scm".
      shared_path::    Full path to remote 'shared' directory, symlinked into
             your app by default. Defaults to "#{deploy_to}/shared".
      ssh_cmd::     Path to ssh. Defaults to "ssh".
      ssh_flags::    Flags for ssh. Defaults to "".
      sudo_cmd::     Path to sudo command. Defaults to "sudo".
      sudo_flags::    Flogs for sudo. Defaults to nil.
      sudo_password::   Asks for password when referenced.
      umask::      Sets your umask value. Defaults to "02".

      == Apache Web Variables:

      web_command::    Command to execute when controlling the web server.
             Defaults to "apachectl".

      == Mongrel App Variables:

      mongrel_address::   Defaults to "127.0.0.1"
      mongrel_clean::   Defaults to false
      mongrel_command::   Defaults to 'mongrel_rails'
      mongrel_conf::    Defaults to "#{shared_path}/mongrel_cluster.conf"
      mongrel_config_script:: Defaults to nil
      mongrel_environment:: Defaults to "production"
      mongrel_group::   Defaults to nil
      mongrel_log_file::  Defaults to nil
      mongrel_pid_file::  Defaults to nil
      mongrel_port::    Defaults to 8000
      mongrel_prefix::   Defaults to nil
      mongrel_servers::   Defaults to 2
      mongrel_user::    Defaults to nil

      == Perforce SCM Variables:

      p4_cmd::      The perforce command to use. Defaults to "p4"
      source::      A perforce SCM worker instance.

      == Subversion SCM Variables:

      source::      A subversion SCM worker instance.
      svn_cmd::     The subversion command to use. Defaults to "svn"

      == Git - The Distributed SCM

      git_cmd::     The git command to use. Defaults to "git"