EC2onRailsを使って、既存のRailsアプリをEC2上で動くようにするための手順のメモです。
EC2onRailsを複数アプリ対応にする方法のメモ
を適用した状態を想定しています。

  1. config/deploy.rb を用意
    サンプルファイルはこちら
    :server_config_files_rootを適当に設定し、指定したPATHにディレクトリを作る。
  2. Capfileを以下のような感じで用意。
    rails>>
    load 'deploy' if respond_to?(:namespace) # cap2 differentiator
    load 'config/deploy'
    require 'ec2onrails/recipes'

set :deploy_to, "/mnt/app/"

override default start/stop/restart tasks

namespace :deploy do
desc <<-"DESC"
Overrides the default Capistrano deploy:start, directly calls
/etc/init.d/mongrel #{application}
DESC
task :start, :roles => :app do
run "/etc/init.d/mongrel start #{application}"
end

desc <<-"DESC"
Overrides the default Capistrano deploy:stop, directly calls
/etc/init.d/mongrel #{application}
DESC
task :stop, :roles => :app do
run "/etc/init.d/mongrel stop #{application}"
end

desc <<-"DESC"
Overrides the default Capistrano deploy:restart, directly calls
/etc/init.d/mongrel #{application}
DESC
task :restart, :roles => :app do
run "/etc/init.d/mongrel restart #{application}"
end
end
<<--
EC2onRailsが上書きしたデフォルトのタスクをさらに上書きして、複数アプリ対応できるようにしています。
 3. 最後に、mongrel_clusterを使うので、config/mongrel_cluster.yml
ファイルを用意します。

yaml>>

cwd: /mnt/app//current
port: 8000
environment: production
pid_file: log/mongrel.pid
servers: 3
<<--
ポート番号はサーバをシェアするアプリ間で適当に割り振ります。

あとは、以下のコマンドを実行してデプロイします。

pre>>
cap ec2onrails:setup
cap deploy:cold
<<--

最後に、EC2onRailsを複数アプリ対応にする方法のメモに書いてあるような、EC2上のApacheのVirtualHostの設定と、ProxyBalancerの設定を行います。

posted by genki genki on Wed 21 May 2008 at 21:02 with 0 comments