[rails]Capistranoを使ってみる&FastCGIで動かしてみる

~/project/suita16で開発してたアプリを/var/www/suita16にデプロイしてみる

$ cap --apply-to ~/project/suita16
$ emacs ~/project/suita16/config/deploy.rb
set :application, "suita16"
set :repository, "file:///var/svn/project/#{application}/trunk"
role :web, "localhost"
role :app, "localhost"
role :db,  "localhost", :primary => true
#role :db,  "db02.example.com", "db03.example.com"
set :deploy_to, "/var/www/suita16" # defaults to "/u/apps/#{application}"
set :user, "jet"            # defaults to the currently logged in user
ssh_options[:keys] = %w(/home/jet/.ssh/id_rsa)

#database.ymlをsubversion内ではdatabase.yml.sampleとしているのでdeploy時にcpするようにupdate_codeタスクをdeploy.rbでオーバーライドする
task :update_code, :except => {  :no_release => true } do
  on_rollback {  delete release_path, :recursive => true }

  source.checkout(self)

  set_permissions

  run <<-CMD
    rm -rf #{release_path}/log #{release_path}/public/system &&
    ln -nfs #{shared_path}/log #{release_path}/log &&
    ln -nfs #{shared_path}/system #{release_path}/public/system &&
    cp #{release_path}/config/database.yml.sample #{release_path}/config/databas
e.yml #一行上の&&とこれを増やした
  CMD
  run <<-CMD
    test -d #{shared_path}/pids &&
    rm -rf #{release_path}/tmp/pids &&
    ln -nfs #{shared_path}/pids #{release_path}/tmp/pids; true
  CMD

  # update the asset timestamps so they are in sync across all servers. This
  # lets the asset timestamping feature of rails work correctly
  stamp = Time.now.utc.strftime("%Y%m%d%H%M.%S")
  asset_paths = %w(images stylesheets javascripts).map {  |p| "#{ release_path}/
pu
blic/#{p}" }
  run "TZ=UTC find #{asset_paths.join(" ")} -exec touch -t #{stamp} {} \\;; true
"

  # uncache the list of releases, so that the next time it is called it will
  # include the newly released path.
  @releases = nil
end

ローカルホストにsshでログインできるようにする

$ cd ~/.ssh
$ cat id_rsa.pub >> authorized_keys
$ chmod 600 authorized_keys

fastcgi関係をインストール

$ sudo apt-get install libapache2-mod_fcgid
$ sudo emacs /etc/apache2/mods-enabled/fcgid.conf
<IfModule mod_fcgid.c>
  AddHandler fcgid-script .fcgi
  SocketPath /var/lib/apache2/fcgid/sock
  DefaultInitEnv  RAILS_ENV production
  IdleTimeout 600
  ProcessLifeTime 3600
  MaxProcessCount 8
  DefaultMinClassProcessCount 3
  DefaultMaxClassProcessCount 3
  IPCConnectTimeout 8
  IPCCommTimeout 48
</IfModule>
$ sudo apache2ctl configtest
$ sudo apache2ctl restart

眠くなったので今日はここまで