ソフト開発するにあたって、レポジトリを含むWiki的なものはあると非常に楽である。
チームからみた場合互いの連携に使え、後から言った言わないの水掛輪を防げるし、
個人から見ても逐一書き込んでおけば色々見返せて便利だ。

以前の会社ではTracを使っていたが、あんまり評判は良くないようだ。
ので、Redmineを導入してみる。

で、一回目やった時には正直あまりにぐだぐだだったのであげたくなかったのだが、失敗した時の解決策の方が
奇麗な成功より参考になりそうなので、一応記述。

インストールの参考にはならないと思うので、奇麗なインストール例は次回の記事で。

yum install -y mysql-server mysql-devel

yumでRubyをインストールしてもいいのだけど、執筆時点でCentOSが
とってくるRubyは1.8.5。このまま行くといろいろ問題が発生するので、
ここは1.8.6にしておく。

wget ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.6-p383.tar.gz

tar zxvf ruby-1.8.6-p383.tar.gz

cd ruby-1.8.6-p383

./configure --prefix=/usr

make

checkinstall

rpm -ivh --nomd5 /usr/src/redhat/RPMS/i386/ruby-1.8.6-1.i386.rpm

checkinstallってなんやねんって人は前の記事を参考。

また、既にRubyをインストールしちゃってて競合が起きてる場合で、
yumでインストールしている人はアンインストールしませう。

yum remove ruby ruby-libs ruby-irb ruby-rdoc ruby-devel

でうまくいくはず。

*ただし、既に他のバージョンに依存するものがある場合は要注意。

次にRubyGemsをインストール

wget http://rubyforge.org/frs/download.php/60718/rubygems-1.3.5.tgz

tar zxvf rubygems-1.3.5.tgz

cd rubygems-1.3.5

ruby setup.rb

Railsのインストール。

gem install rails --include-dependencies

記録用にログとか残す。

Successfully installed activesupport-2.3.4
Successfully installed activerecord-2.3.4
Successfully installed rack-1.0.0
Successfully installed actionpack-2.3.4
Successfully installed actionmailer-2.3.4
Successfully installed activeresource-2.3.4
Successfully installed rails-2.3.4
7 gems installed
Installing ri documentation for activesupport-2.3.4...
Installing ri documentation for activerecord-2.3.4...
Installing ri documentation for rack-1.0.0...
Installing ri documentation for actionpack-2.3.4...
Installing ri documentation for actionmailer-2.3.4...
Installing ri documentation for activeresource-2.3.4...
Installing ri documentation for rails-2.3.4...
Installing RDoc documentation for activesupport-2.3.4...
Installing RDoc documentation for activerecord-2.3.4...
Installing RDoc documentation for rack-1.0.0...
Installing RDoc documentation for actionpack-2.3.4...
Installing RDoc documentation for actionmailer-2.3.4...
Installing RDoc documentation for activeresource-2.3.4...
Installing RDoc documentation for rails-2.3.4...

…残す意味ないような

Mongrelインストール。こっちもついでに。

gem install mongrel
Successfully installed gem_plugin-0.2.3
Successfully installed daemons-1.0.10
Successfully installed cgi_multipart_eof_fix-2.5.0
Successfully installed mongrel-1.1.5
4 gems installed
Installing ri documentation for gem_plugin-0.2.3...
Installing ri documentation for daemons-1.0.10...
Installing ri documentation for cgi_multipart_eof_fix-2.5.0...
Installing ri documentation for mongrel-1.1.5...
Installing RDoc documentation for gem_plugin-0.2.3...
Installing RDoc documentation for daemons-1.0.10...
Installing RDoc documentation for cgi_multipart_eof_fix-2.5.0...
Installing RDoc documentation for mongrel-1.1.5...

Redmine用のディレクトリを作成(この場合は /var/redmine、どこでも良い)して、
SVNをつかってRedmineをチェックアウトする

mkdir /var/redmine

cd /var/redmine

svn checkout http://redmine.rubyforge.org/svn/trunk/ .

次にMysqlのRedmine用データベースを作成する。

mysql -u root
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

にゅ?
ググってみるとmysqlが起動してない模様。そりゃ接続できんね。

/etc/rc.d/init.d/mysqld start

ついでに起動時に動くよう設定。

chkconfig mysqld on
chkconfig --list mysqld
mysqld          0:off   1:off   2:on    3:on    4:on    5:on    6:off

んだば再度

mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or ¥g.
Your MySQL connection id is 2
Server version: 5.0.45 Source distribution

Type 'help;' or '¥h' for help. Type '¥c' to clear the buffer.

mysql> create database redmine character set utf8;
Query OK, 1 row affected (0.00 sec)
mysql> exit
Bye

ここで明示的にredmineデータベースをUTF8に設定しておかないと色々文字化けで
苦しんだりするかもしれないので注意しましょう。

で、次はRedmineの設定を弄る。

サンプル用の設定ファイルをコピーして使う。
usernameとpasswordは先ほど決めたものに変更、developmentとtestのdatabaseをredmine
にするのは、元のままだと同名のデータベースを作らなければならず、Redmineでは最初から
運用するため使わないので無駄となる。よって運用用のデータベースと同じにしてしまう。

cp config/database.yml.example config/database.yml

以下のようにデータベースの設定を行う。

production:
  adapter: mysql
  database: redmine
  host: localhost
  username: root
  password:
  encoding: utf8
 socket: /var/lib/mysql/mysql.sock

development:
  adapter: mysql
  database: redmine
  host: localhost
  username: root
  password:
  encoding: utf8

test:
  adapter: mysql
  database: redmine
  host: localhost
  username: root
  password:
  encoding: utf8

まあ、実際にはProductionしか使わないのであるが、後学のために
三つとも書いておく。今後のRailsプロジェクトでコピペに使えるし。
databaseのところ書き換え忘れてエラー出しそうである。

Railsのデータベースのマイグレーション

rake db:migrate RAILS_ENV="production"
(in /var/redmine)
Missing the Rails 2.2.2 gem. Please `gem install -v=2.2.2 rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed

これだから発展途上の言語は嫌いデース。

解説しておくと、Redmineは開発者が作った環境に依存しているため、特にRailsのバージョンなんかは露骨にその動きに影響されるわけで、
こちらのバージョンが違うとこういう問題が起きるのですね。対処法としては、
1)Railsのバージョンを合わせる。
2)エラーメッセージにあるようにRAILS_GEM_VERSIONを自分のRailsバージョンに合わせる。

とりあえず2)でいってみましょう。
今後2.2.2固定でやっていくとは限らないし

わぁ、さっきログとっておいたのが役に立ったね♪

vim /config/enviroment.rb

# Specifies gem version of Rails to use when vendor/rails is not present
RAILS_GEM_VERSION = '2.2.2' unless defined? RAILS_GEM_VERSION

RAILS_GEM_VERSION = '2.3.4' unless defined? RAILS_GEM_VERSION

以上のように変更。変更バージョンは適切に変更してください。

rails -v

とかで調べて。

rake db:migrate RAILS_ENV="production"
(in /var/redmine)
rake aborted!
A key is required to write a cookie containing the session data. Use config.action_controller.session = { :key => "_myapp_session", :secret => "some secret phrase" } in config/environment.rb

(See full trace by running task with --trace)

わぁまた知らんエラーが

注意書きに則り、

vim config/environment.rb

下記を末尾に追加する

config.action_controller.session = { :key => "_myapp_session", :secret => "適当な英数字" }

再再度挑戦

rake db:migrate RAILS_ENV="production"
(in /var/redmine)
!!! The bundled mysql.rb driver has been removed from Rails 2.2. Please install the mysql gem and try again: gem install mysql.
rake aborted!
no such file to load -- mysql

はいだらーーー!

まぁ、解決策がすぐ分かるエラーを出してくれる分にはいいですね、ええ。

*実はここでruby1.8.5だと1.8.6以降じゃないとインストールできないとか抜かされるので、ちゃんと1.8.6にしないと駄目なのだ。

gem install mysql

成功。
では再々々々挑戦

rake db:migrate RAILS_ENV="production"

(in /var/redmine)
==  Setup: migrating ==========================================================
-- create_table("attachments", {:force=>true})
   -> 0.1660s
-- create_table("auth_sources", {:force=>true})

省略

成功した。
*実はここでmysql-develをインストールしてなくて色々うまくいかなったのだが、
そこは割愛。

デフォルトデータの読み込み
言語設定ではjaを選択

rake load_default_data RAILS_ENV="production"
(in /var/redmine)

Select language: bg, bs, ca, cs, da, de, el, en, es, fi, fr, gl, he, hu, it, ja, ko, lt, nl, no, pl, pt, pt-BR, ro, ru, sk, sl, sr, sv, th, tr, uk, vi, zh, zh-TW [en] ja

さて、いけたようなので、いよいよ起動してみる。

ruby script/server
=> Booting WEBrick
=> Rails 2.3.4 application starting on http://0.0.0.0:3000
/usr/lib/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/dependencies.rb:443:in `load_missing_constant': uninitialized constant ApplicationController (NameError)
    from /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/dependencies.rb:80:in `const_missing'

    from /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/dependencies.rb:92:in `const_missing'
    from /var/redmine/app/controllers/account_controller.rb:18
    from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'

    from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
    from /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/dependencies.rb:158:in `require'

    from /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.4/lib/active_support/dependencies.rb:265:in `require_or_load_without_engine_additions'
    from /var/redmine/vendor/plugins/engines/lib/engines/rails_extensions/dependencies.rb:124:in `require_or_load'

     ... 18 levels...
    from /usr/lib/ruby/gems/1.8/gems/rails-2.3.4/lib/commands/server.rb:84
    from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
    from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'

    from script/server:3

ググる。どうも本格的に2.3で運用するのはあんまり向いてないらしい。Railsをプロジェクトごとに素直に切り替えた方がよかったのかなぁと後悔。

cd app/controllers

どうやらコントローラの一つの名前が変更されている模様。

mv application.rb application_controller.rb

ruby script/server

が、これでもエラーが出てしまいうまくゆかず。
その後色々やってもうまくいきませんでした。
もう少しがんばればできたかも知れないが、問題の根幹はRails2.2.2用のRedmineを無理やり2.3.4で動かそうとしたことなのである。…あの時、Railsをあわせるを選んでおけば…

GAME OVER

以下二週目に続く、まさかここまでそのままやった人はいないと思うが、やってしまった記録としてどう対処するかも記録する。
まぁ、ぶっちゃけ下記の手順を行うことによりRedmineが正常に動くようになる。

まず、先ほど変えてしまったコントローラの名前を元に戻し、

mv application_controller.rb application.rb

Redmineの環境設定でRailsのバージョンを2.2.2に。

vim /config/enviroment.rb
# Specifies gem version of Rails to use when vendor/rails is not present
RAILS_GEM_VERSION = '2.3.4' unless defined? RAILS_GEM_VERSION

RAILS_GEM_VERSION = '2.2.2' unless defined? RAILS_GEM_VERSION

最初から2.2.2を選んだ場合の手順書についてはこちら

下記サイトを参照。
http://blog.apecell.com/2008/04/02/id/38
http://blog.livedoor.jp/leaveanest/archives/846257.html
http://uprush.net/2009/06/redmine%E3%82%92centos5%E3%81%AB%E3%82%A4%E3%83%B3%E3%82%B9%E3%83%88%E3%83%BC%E3%83%AB/
http://d.hatena.ne.jp/snusmum/20090827/1251380110
http://blog.livedoor.jp/maru_tak/archives/50664746.html