2010-09-07

プライベートな問題追跡システムが欲しい

コンピュータを使った作業で、その結果が形として(ビットやバイトで)残るのであれば(とくにそれがテキスト系なら)バージョン管理ツールを使うべきだ。一方、公開であれ非公開であれ、コンピュータを使った作業をプロジェクトとして扱うなら問題追跡ツールを使う方が良い。ソフトウェア工学という名の経験則の集積の中で、この 2 つの事実だけは、プログラマであれば誰もが認めるものだろう。

Open Source Software 開発プロジェクトのように公開するものであれば、外部の(つまりインターネット上の)サービスを使うことになる。けれど、私的なプロジェクトであればどうか。自宅内のサーバに、あるいは普段使いのデスクトップマシンに、なんならいつも持ち歩くノート型パソコンにこれらのツールも用意したくなる。

バージョン管理ツール(コードリポジトリ)は Git が良いとして、問題追跡ツールは何が良いだろう? 候補として頭に浮かんだのは、Ruby (と Rails) で作られた Redmine に、Python で作られた Trac の 2 つ。

数年前のことになるが、 Trac には初期の頃にインストールで苦労した覚えがある。いまでは、もうそんなことはない(はずだ)とわかっていても、少しためらう気持ちがわいてくる。そんなこともあって、今回、Redmine を Mac mini (Snow Leopard Server) にインストールすることにした。

インストール先を、普段使いの iMac でなく、mini にしたのは、iMac 以外の機器でも(MacBook、iPadなど、ひょっとして iPhone でも)使うことがあるかもしれないから。iMac は、わたしがその前に座っていないときはスリープさせているが、mini の方は外出するときと夜眠るっている間を除いて常時稼動している。iMac の前にいないときにも使いたいと思ったら mini の方に入れることになる。

Redmine のインストール

公式ドキュメントの Installing Redmine にはインストールに必要なソフトウェアが列挙されている。まずはそれを見ながら Snow Leopard Server (10.6.4) の状況をチェックする。

前提となるソフトウェア
Ruby
[mini] mnbi% which ruby
/usr/bin/ruby
[mini] mnbi% ruby -v
ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]

Ruby、OK。

Rails
[mini] mnbi% which rails
/usr/bin/rails
[mini] mnbi% rails -v
Rails 2.3.5

Rails、OK。

Rack
[mini] mnbi% gem list rack

*** LOCAL GEMS ***

rack (1.0.1)

Rack、OK。

RubyGems
[mini] mnbi% which gem
/usr/bin/gem
[mini] mnbi% gem --version
1.3.5
[mini] mnbi% sudo gem update --system
Password:
Updating RubyGems
Updating rubygems-update
Successfully installed rubygems-update-1.3.7
Updating RubyGems to 1.3.7
Installing RubyGems 1.3.7
RubyGems 1.3.7 installed

=== 1.3.7 / 2010-05-13

NOTE:

http://rubygems.org is now the default source for downloading gems.

You may have sources set via ~/.gemrc, so you should replace
http://gems.rubyforge.org with http://rubygems.org

http://gems.rubyforge.org will continue to work for the forseeable future.

New features:
[...snip...]
[mini] mnbi% gem --version
1.3.7

RubyGems は、標準でインストールされているのは 1.3.5。それでも問題はないが、ついでなのでアップデートしておいた。RubyGems、OK。

Rake
[mini] mnbi% which rake
/usr/bin/rake
[mini] mnbi% rake --version
rake, version 0.8.3

Rack、OK。

MySQL
[mini] mnbi% man mysql
[mini] mnbi% which mysql
/usr/bin/mysql
[mini] mnbi% mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 14
Server version: 5.0.88-log Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> quit
Bye

Snow Leopard Server には MySQL サーバが標準でインストールされている。が、このインストールには少々問題がある。というのも、クライアントとライブラリなどの一部のファイルがインストールされていないのだ。おそらく、サーバの稼動に不要なものが削られているのだろう。今回はこの欠けているファイルに用がある。mysql.gem をインストールするのに必要なのだ。

幸い、解決策は判明している。Apple が残りのファイルもふくめてバイナリパッケージを配布しているのだ。この問題および解決策は、この記事(→ Installing MySQL Ruby Gem in Snow Leopard Server)で知った。あらかじめ Snow Leopard Server に Redmine をインストールするための情報を集めている(ググっている)ときに見つけた。

↑の記事では 10.6.2 用なので MySQL-49.binaries.tar.gz となっているが、現行の 10.6.4 では MySQL-53.binaries.tar.gz をダウンロードしなければならない。以下がそのファイルへの直リンクだ。

↑の記事にも書いてあるが、このファイルは Apple の配布サイトにある一覧表には載っていない(そのうち載るのかもしれないが)。上記の 53 は、49 の直リンクを手で書き換えて探した。50、51、...、と増やして行き、54 以降はファイルが見つからないというエラーページが帰ってきたのだ。よって、2010-09-07 時点では 53 が最新版だ。実際に、収められているファイルのタイムスタンプは 10.6.4 にインストールずみのものと一致している。

以下が mysql.gem のインストールを実行した結果だ。

[mini] mnbi% ls ~/Downloads
MySQL-53.binaries.tar.gz
[mini] mnbi% sudo tar -xzf Downloads/MySQL-53.binaries.tar.gz -C /
[mini] mnbi% sudo env ARCHFLAGS="-arch x86_64" gem install mysql
Building native extensions.  This could take a while...
Successfully installed mysql-2.8.1
1 gem installed
Installing ri documentation for mysql-2.8.1...

No definition for next_result
[...snip...]

No definition for error_sqlstate
Installing RDoc documentation for mysql-2.8.1...

No definition for next_result
[...snip...]

No definition for error_sqlstate
[mini] mnbi% gem list mysql

*** LOCAL GEMS ***

mysql (2.8.1)

以上で前提条件は揃った。

インストール

Installing Redmine のステップ 1 〜 6 までを実行する。前提条件をクリアしているので何の問題も起きずに完了。

Webrick で試運転

Installing Redmine のステップ 8 を実行する。ステップ 7 のパーミッションについては本番稼動のときに考えることにして、ここでは省略。試運転をするユーザと redmine ディレクトリの所有者が一致しているので問題は起きない。

[mini] mnbi% ruby script/server webrick -e production

問題なく動いた。admin のパスワードを変えて、普段使いのユーザを作ったら試運転終了。

本番稼動は Apache で

Installing Redmine にも webrick はインストール時のテストだけにしておけ、と書かれている。本番稼動では Passenger か Mongrel を使え、と。Mongrel は Snow Leopard Server に標準でインストールされているが、Passenger はない。簡単に調べて(ググって)みると Mongrel は単独の HTTP サーバで、Passenger は Apache のモジュールだとわかった。

(やったことがないので) Mongrel を動かすことも考えたが、自動起動の設定や実行ユーザのことで悩みそうなので、今回は見送った。Apache のモジュールで動かすのであれば起動のことや実行ユーザのことは気にする必要はない。

Apache のモジュールとして Rails アプリを動かす
Passenger

(ググって見つけた)この記事(→ SnowLeopardにRedmineをインストールしてApache2 + Passengerで動かす)に書かれている通り、2 つのコマンドで Passenger のインストールを実行する。

まずは Passenger 本体。

[mini] mnbi% sudo gem install passenger
Building native extensions.  This could take a while...
Successfully installed passenger-2.2.15
1 gem installed
Installing ri documentation for passenger-2.2.15...
Installing RDoc documentation for passenger-2.2.15...

続いて、Apache のモジュール。以下の実行例では一部長い行をバックスラッシュで折り返している。

[mini] mnbi% rehash
[mini] mnbi% which passenger-install-apache2-module
/usr/bin/passenger-install-apache2-module
[mini] mnbi% sudo passenger-install-apache2-module
Welcome to the Phusion Passenger Apache 2 module installer, v2.2.15.

This installer will guide you through the entire installation process. It
shouldn't take more than 3 minutes in total.

Here's what you can expect from the installation process:

 1. The Apache 2 module will be installed for you.
 2. You'll learn how to configure Apache.
 3. You'll learn how to deploy a Ruby on Rails application.

Don't worry if anything goes wrong. This installer will advise you on how to
solve any problems.

Press Enter to continue, or Ctrl-C to abort.


--------------------------------------------

Checking for required software...

 * GNU C++ compiler... found at /usr/bin/g++
 * Ruby development headers... found
 * OpenSSL support for Ruby... found
 * RubyGems... found
 * Rake... found at /usr/bin/rake
 * rack... found
 * Apache 2... found at /usr/sbin/httpd
 * Apache 2 development headers... found at /usr/sbin/apxs
 * Apache Portable Runtime (APR) development headers... \
found at /usr/bin/apr-1-config
 * Apache Portable Runtime Utility (APU) development headers... \
found at /usr/bin/apu-1-config

--------------------------------------------
Compiling and installing Apache 2 module...
[...snip...]

--------------------------------------------
The Apache 2 module was successfully installed.

Please edit your Apache configuration file, and add these lines:

   LoadModule passenger_module \
/Library/Ruby/Gems/1.8/gems/passenger-2.2.15/ext/apache2/mod_passenger.so
   PassengerRoot /Library/Ruby/Gems/1.8/gems/passenger-2.2.15
   PassengerRuby \
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby

After you restart Apache, you are ready to deploy any number of Ruby on Rails
applications on Apache, without any further Ruby on Rails-specific
configuration!

Press ENTER to continue.


--------------------------------------------
Deploying a Ruby on Rails application: an example

Suppose you have a Rails application in /somewhere. Add a virtual host to your
Apache configuration file and set its DocumentRoot to /somewhere/public:

   <VirtualHost *:80>
      ServerName www.yourhost.com
      DocumentRoot /somewhere/public    # <-- be sure to point to 'public'!
      <Directory /somewhere/public>
         AllowOverride all              # <-- relax Apache security settings
         Options -MultiViews            # <-- MultiViews must be turned off
      </Directory>
   </VirtualHost>

And that's it! You may also want to check the Users Guide for security and
optimization tips, troubleshooting and other useful information:

  /Library/Ruby/Gems/1.8/gems/passenger-2.2.15/doc/Users guide Apache.html

Enjoy Phusion Passenger, a product of Phusion (www.phusion.nl) :-)
http://www.modrails.com/

Phusion Passenger is a trademark of Hongli Lai & Ninh Bui.

後半に表示された情報は、後で Apache の設定変更に必要なものだ。

DNS の設定

本番環境では http://mini.private/redmine/ のような URL ではなく、http://redmine.private/ でアクセスしたい。そのために、mini (Snow Leopard Server) 上の DNS でエイリアスを追加する。

Apache の設定変更

Passenger の Apache モジュールをインストールした際に表示されたメッセージにしたがって、Apache の設定に対して以下の 3 点の変更を加える。

  1. Passenger モジュールのロード
  2. Passenger モジュールに対する設定 (PassengerRoot と PassengerRuby)
  3. バーチャルホストの追加

1. と 3. は Snow Leopard Server の「サーバ管理.app」で行う。しかし、2. のモジュール独自の変数の設定はこのアプリでは行えない。仕方なく /etc/apache2/httpd.conf に手動で書き入れた。

Redmine ディレクトリのアクセス権

Installing Redmine にあるステップ 7 「Setting up permissions」を参考に、Redmine ディレクトリにある以下のディレクトリの所有者を Apache の実行ユーザに変えておく。

  • files
  • log
  • tmp
  • public/plugin_assets

Redmine が Apache のモジュールとして動くのだから、Apache を実行するユーザで書き込みできなければならない。

インストールを振り返る

特に苦労した箇所はない。近頃の、Open Source Software はインストール手順もしっかりまとめられていて、そこに書かれているステップを順に実行していけば問題なく作業が完了する。今回のインストールであえて苦言を呈するとすれば、少々面倒だと感じる点か。とくに Snow Leopard Server で標準インストールされている MySQL に配布ファイルの一部が足りないっていうのは困りものだ。

Redmine のインストールを簡単にする一番良い方法は Apple が Mac OS X Server の標準コンポーネントとして Redmine を取り込んでくれることだな(インストールが不要になる)。ま、他のプロジェクト管理ソフト(今回、欲しかったのは問題追跡ツールだけなんだがね)でも良いけれど。

Git リポジトリとの連携も試したいところだが、今のところ mini にリポジトリはないから、それはまた別の機会に。

関連リンク

関連記事

0 件のコメント:

コメントを投稿