Tracの導入@Debian etch

Tracはメジャーなオープンソースのバグトラッキングシステム。

Subversionと連携させるために、事前にリポジトリを作っておくこと。(ここでは省略します)
ここでは/home/svnに作っているとします。
さらに、revision 1がないと、Trac初期化時に以下のエラーになるので注意。

~省略~
Failed to initialize environment. ('No such revision 1', 160006)
raceback (most recent call last):
File "/var/lib/python-support/python2.4/trac/scripts/admin.py", line 628, in do_initenv
repos = self.__env.get_repository()Failed to initialize environment. ('No such revision 1', 160006)
Traceback (most recent call last):
File "/var/lib/python-support/python2.4/trac/scripts/admin.py", line 628, in do_initenv
repos = self.__env.get_repository()
~省略~

インストール

まずは

# apt-get install trac

次にtrac-adminコマンドで初期化

# mkdir /home/trac
# trac-admin /home/trac
...
Project Name [My Project]> ←プロジェクト名を入力
...
Database connection string [sqlite:db/trac.db]> ←デフォルトのsqliteを使用するのでそのままリターン
...
Repository type [svn]> ←リターン
...
Path to repository [/path/to/repos]> /home/svn ←入力
...
Templates directory [/usr/share/trac/templates]> ←リターンCreating and Initializing Project .....省略
Congratulations!

起動確認

tracには簡易的なWebサーバが付属しています。これを使って起動確認をしてみます。

# tracd --port 80 /home/trac

これでブラウザからアクセスできればOK

Apacheとの連携

アクセスユーザの設定

# htpasswd パスワードファイル名(/etc/apache/passwdなど) ユーザ名

tracをapacheに追加してあげます。

# vi /etc/apache2/sites-available/trac

アクセスはポート8080にしています。
ファイル内容

Listen 8080
<VirtualHost *:8080>
ServerAdmin webmaster@localhost
DocumentRoot /usr/share/trac/htdocs/
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /home/httpd/root/>
AllowOverride AuthConfig Limit
</Directory>ScriptAlias /trac /usr/share/trac/cgi-bin/trac.cgi
<Location "/trac">
SetEnv TRAC_ENV "/home/trac"
</Location>
<LocationMatch "/trac/login">
AuthType Basic
AuthName "Trac"
AuthUserFile パスワードファイル名
Require valid-user
</LocationMatch>
ServerSignature Off
</VirtualHost>

Pluginの導入

チケットのタイプとかコンポーネントとかの管理がコマンドラインからしかできません。
なので、WebAdminというプラグインを導入します。
プラグインのeggファイルを扱うためにpythonのツールをインストール

# apt-get install python-setuptools
# wget http://trac.edgewall.org/attachment/wiki/WebAdmin/TracWebAdmin-0.1.2dev_r4240-py2.4.egg.zip?format=raw
# mv TracWebAdmin-0.1.2dev_r4240-py2.4.egg.zip?format=raw /home/trac/plugin/TracWebAdmin-0.1.2dev_r4240-py2.4.egg

/home/trac/conf/trac.iniに以下のように記述

[components]
webadmin.* = enabled

サーバ再起動は必要ないはずですが、アクセスすると以下のようなエラーになります。

(抜粋)

ExtractionError: Can't extract file(s) to egg cache
The following error occurred while trying to extract file(s) to the Python egg cache:
[Errno 13] Permission denied: '/var/www/.python-eggs'
The Python egg cache directory is currently set to:
/var/www/.python-eggs

これはeggファイルキャッシュディレクトリにアクセス権限がないからです。
なので、apacheの設定でキャッシュディレクトリを以下のように設定してあげます。

<Location "/trac">
SetEnv TRAC_ENV "/home/trac"
SetEnv PYTHON_EGG_CACHE /tmp/traceggcache ★追加
</Location>

そして、以下を実行

# mkdir /tmp/traceggcache
# chown www-data:www-data /tmp/traceggcache
# /etc/init.d/apache reload

あと、デフォルトだとADMIN権限を持っていませんので、ADMIN権限を与えます。

# trac-admin /home/trac permission add ユーザ名 TRAC_ADMIN

これで正常にadminとう項目がTrac上に出てきます。

DBについて

デフォルトではSQLiteが使用されます。Debian etchのsqliteはバージョン2系で、sqliteコマンドでは以下のようなエラーになります。

Unable to open database "tracbak.db": file is encrypted or is not a database

3系をインストールしてアクセスしましょう。

# apt-get install sqlite3
# sqlite3 dbファイル名

mod_pythonの導入

デフォルトのcgiモードだと、だんだんと動作が鈍くなってきます。
以下の通りmod_pythonを入れると速くなります。

# apt-get install libapache2-mod-python

apacheの設定ファイル tracを編集

<Location "/trac">
#SetEnv TRAC_ENV "/home/trac"
SetEnv PYTHON_EGG_CACHE /tmp/traceggcache
SetHandler mod_python
PythonHandler trac.web.modpython_frontend
PythonOption TracEnv /home/trac
</Location>
タイトルとURLをコピーしました