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

  1. config/deploy.rb を用意 (サンプルファイルはこちら:server_config_files_rootを適当に設定し、指定したPATHにディレクトリを作る。
  2. Capfileを以下のような感じで用意。
       1  load 'deploy' if respond_to?(:namespace) # cap2 differentiator
       2  load 'config/deploy'
       3  require 'ec2onrails/recipes'
       4  
       5  set :deploy_to, "/mnt/app/<app_name>"
       6  
       7  # override default start/stop/restart tasks
       8  namespace :deploy do
       9    desc <<-"DESC"
      10      Overrides the default Capistrano deploy:start, directly calls \
      11      /etc/init.d/mongrel #{application}
      12    DESC
      13    task :start, :roles => :app do
      14      run "/etc/init.d/mongrel start #{application}"
      15    end
      16  
      17    desc <<-"DESC"
      18      Overrides the default Capistrano deploy:stop, directly calls \
      19      /etc/init.d/mongrel #{application}
      20    DESC
      21    task :stop, :roles => :app do
      22      run "/etc/init.d/mongrel stop #{application}"
      23    end
      24  
      25    desc <<-"DESC"
      26      Overrides the default Capistrano deploy:restart, directly calls \
      27      /etc/init.d/mongrel #{application}
      28    DESC
      29    task :restart, :roles => :app do
      30      run "/etc/init.d/mongrel restart #{application}"
      31    end
      32  end
    
    EC2onRailsが上書きしたデフォルトのタスクをさらに上書きして、複数アプリ対応できるようにしています。  3. 最後に、mongrel_clusterを使うので、config/mongrel_cluster.yml ファイルを用意します。
       1  ---
       2  cwd: /mnt/app/<app_name>/current
       3  port: 8000
       4  environment: production
       5  pid_file: log/mongrel.pid
       6  servers: 3
    
    ポート番号はサーバをシェアするアプリ間で適当に割り振ります。

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

   1  cap ec2onrails:setup
   2  cap deploy:cold

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

posted by Png genki on Wed 21 May 2008 at 18:27

Comments:

or Preview
Social Bookmarks
  • Delicious
  • B_entry590
  • Clip_16_12_w
Services from s21g
twpro(ツイプロ)
Twitterプロフィールを快適検索
地価2009
土地の値段を調べてみよう
MyRestaurant
自分だけのレストラン手帳
Formula
ブログに数式を埋め込める数式コミュニティ