retrospectivaのインストール

RoRによるTracクローンretrospectivaをインストールしてみました。retrospectivaの公式サイトではGitHub - dim/retrospectiva: Open source, web-based agile project management, featuring: Goal planner, Story management, Issue-tracker, Code review, SCM Integration, Wiki & Blog. It is intended to assist the collaborative aspect of work carried out by software development teams.でかなり親切なインストール手順が説明されていて、使いはじめる前から好印象です。

以前インストールしたTypoApacheをリバースプロキシにしてMongrelで動かしましたが、今回は親切な公式ドキュメントを読みつつ、Apacheのmod_fcgidでの動作にチャレンジしてみることにします。

retrospectivaはtrunk(r493)を使いました。railsのバージョンは2.0.2です。はじめにリリース1.0を試してみたのですが、rakeするときにActionView::Base.load_helpers()でwrong number of argumentsが出てしまい、動かせませんでした。詳しく調べていませんがrailsのバージョン依存があるのかもしれません。

svn co http://retrospectiva.googlecode.com/svn/trunk retrospectiva

retrospectivaに付属のconfig/database.yml.todoはMySQLを使う設定になっていますが、SQLite3を使う方が何かと小回りが利くため、config/database.ymlを以下のように設定してみました。データベースの設定が終わったらrakeします。

production:
  adapter: sqlite3
  database: retrospectiva

development:
  adapter: sqlite3
  database: retrospectiva_development

<%= ['sqlite3', 'lt3'].include?(ENV['TDB']) ? 'test' : 'test_sqlite3' %>:
  adapter: sqlite3
  database: tmp/test_db

<%= ['postgresql', 'pg'].include?(ENV['TDB']) ? 'test' : 'test_postgresql' %>:
  adapter: postgresql
  database: retrospectiva_test
  username: root
  password:
  host: localhost

<%= ['mysql', 'my', '', nil].include?(ENV['TDB']) ? 'test' : 'test_mysql' %>:
  adapter: mysql
  database: retrospectiva_test
  username: root
  password:
  encoding: utf8
  socket: /var/run/mysqld/mysqld.sock
rake RAILS_ENV=production db:retro:load

WEBRickで動かす場合はscript/serverを実行すればすぐに使用可能ですが、Apache+mod_fcgidで動かすには、Apacheの設定とpublic/.htaccessをいじる必要があります。この方法もGitHub - dim/retrospectiva: Open source, web-based agile project management, featuring: Goal planner, Story management, Issue-tracker, Code review, SCM Integration, Wiki & Blog. It is intended to assist the collaborative aspect of work carried out by software development teams.に詳しく書かれています。

まずApache側はRAILS_ENVの設定と、retrospectivaのpublicディレクトリで.htaccessが有効になるよう、AllowOverrideディレクティブを設定します。以下は公式ドキュメントからの転載です。

<VirtualHost *>
  ServerName your.site.com
  ServerAdmin webmaster@your.site.com
  DocumentRoot /var/www/retrospectiva/public/
  ErrorLog /var/log/apache2/retrospectiva-error.log
  CustomLog /var/log/apache2/retrospectiva-access.log combined

  DefaultInitEnv RAILS_ENV production

  <Directory /var/www/retrospectiva/public/ >
    Options ExecCGI FollowSymLinks
    AllowOverride all
    Order allow,deny
    Allow from all
  </Directory>

</VirtualHost>

続いてpublic/.htaccessを編集して、単なるFastCGIではなくfcgidで動作するよう設定します。編集するのは2箇所だけ。.fcgifastcgi-scriptではなくfcgid-scriptで処理するよう設定し、rewriteにより実行されるスクリプトを.cgiから.fcgiへ変更します。僕の最終的な.htaccessは以下のようになりました。

# General Apache options
#AddHandler fastcgi-script .fcgi
AddHandler fcgid-script .fcgi
#AddHandler cgi-script .cgi
Options +FollowSymLinks +ExecCGI

# If you don't want Rails to look in certain directories,
# use the following rewrite rules so that Apache won't rewrite certain requests
#
# Example:
#   RewriteCond %{REQUEST_URI} ^/notrails.*
#   RewriteRule .* - [L]

# Redirect all requests not available on the filesystem to Rails
# By default the cgi dispatcher is used which is very slow
#
# For better performance replace the dispatcher with the fastcgi one
#
# Example:
#   RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
RewriteEngine On

# If your Rails application is accessed via an Alias directive,
# then you MUST also set the RewriteBase in this htaccess file.
#
# Example:
#   Alias /myrailsapp /path/to/myrailsapp/public
#   RewriteBase /myrailsapp

RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]

# In case Rails experiences terminal errors
# Instead of displaying this message you can supply a file here which will be rendered instead
#
# Example:
#   ErrorDocument 500 /500.html
ErrorDocument 500 "<h2>Application error</h2>Rails application failed to start properly"

以上でインストールは終わりです。この状態でhttp://your.site.com/retrospectiva/public/へアクセスするとretrospectivaのログイン画面が表示されます。もしURLを整えるためApacheの設定でaliasする場合は、.htaccessもコメント通りにRewriteBaseを設定すれば良いようです。