Tracが壊れて復旧した

一緒に仕事してるチームがSCMをSubversionからGitへ移行したためTracからGitのリポジトリへアクセスできるようにトライしたら大変なことになったので復旧までの顛末を書いておきます。


まず環境。

OS CentOS 5.1
PostgreSQL 8.3.1
Python 2.5.2
DB Driver? pyPgSQL 2.5.1
Trac 0.10.4-ja-1

で、壊れるまでの手順

  1. TracからGitを参照するには、GitPluginなるものを入れれば良いという事が分かってこのサイトを参考にインストールしようとした
  2. easy_installが入ってないのでこのサイトを見てインストールした
  3. 上述のGitPluginをインストールしてapacheを再起動した
  4. .egg_cacheが書きこめないと怒られたので書き込み権限を付与してapacheを再起動
  5. プロジェクトページを開くと(多分)データベースと、設定の状況があってないと怒ってるメッセージが表示された
  6. resyncしなきゃとtrac-adminを実行しようとすると以下のメッセージが表示された
Traceback (most recent call last):
  File "/opt/trac/bin/trac-admin", line 21, in <module>
    from trac.scripts.admin import run
ImportError: No module named scripts.admin

復旧方法を探しても「Tracのアンインストール」と言う情報しか出てこないので、GitPluginのインストールログを眺めてみることにしました。ログはこんな感じ。

Downloading https://github.com/hvr/trac-git-plugin/zipball/v0.12.0.5
Processing v0.12.0.5
Running hvr-trac-git-plugin-70713b1/setup.py -q bdist_egg --dist-dir /tmp/easy_install-rpgbdA/hvr-trac-git-plugin-70713b1/egg-dist-tmp-Vjx4Vy
zip_safe flag not set; analyzing archive contents...
Adding TracGit 0.12.0.5dev to easy-install.pth file

Installed /opt/python/2.5.2/lib/python2.5/site-packages/TracGit-0.12.0.5dev-py2.5.egg
Processing dependencies for TracGit==0.12.0.5dev
Searching for Trac>=0.12
Reading http://pypi.python.org/simple/Trac/
Reading http://trac.edgewall.org/
Reading http://trac.edgewall.org/wiki/TracDownload
Reading http://trac.edgewall.com/
Reading http://projects.edgewall.com/trac
Reading http://projects.edgewall.com/trac/wiki/TracDownload
Best match: Trac 0.12.3
Downloading http://download.edgewall.org/trac/Trac-0.12.3.zip
Processing Trac-0.12.3.zip
Running Trac-0.12.3/setup.py -q bdist_egg --dist-dir /tmp/easy_install-5aIdE3/Trac-0.12.3/egg-dist-tmp-7EmFnC
Genshi is needed by Trac setup, pre-installing
Searching for Genshi>=0.6,<0.7dev
Reading http://pypi.python.org/simple/Genshi/
Reading http://genshi.edgewall.org/
Reading http://genshi.edgewall.org/wiki/Download
Best match: Genshi 0.6
Downloading http://ftp.edgewall.com/pub/genshi/Genshi-0.6-py2.5.egg
Processing Genshi-0.6-py2.5.egg
Moving Genshi-0.6-py2.5.egg to /tmp/easy_install-5aIdE3/Trac-0.12.3

Installed /tmp/easy_install-5aIdE3/Trac-0.12.3/Genshi-0.6-py2.5.egg
Adding Trac 0.12.3 to easy-install.pth file
Installing trac-admin script to /opt/python/bin
Installing tracd script to /opt/python/bin

Installed /opt/python/2.5.2/lib/python2.5/site-packages/Trac-0.12.3-py2.5.egg
Searching for Genshi>=0.6,<0.7dev
Reading http://pypi.python.org/simple/Genshi/
Reading http://genshi.edgewall.org/
Reading http://genshi.edgewall.org/wiki/Download
Best match: Genshi 0.6
Downloading http://ftp.edgewall.com/pub/genshi/Genshi-0.6-py2.5.egg
Processing Genshi-0.6-py2.5.egg
Moving Genshi-0.6-py2.5.egg to /opt/python/2.5.2/lib/python2.5/site-packages
Adding Genshi 0.6 to easy-install.pth file

Installed /opt/python/2.5.2/lib/python2.5/site-packages/Genshi-0.6-py2.5.egg
Finished processing dependencies for TracGit==0.12.0.5dev

ん?Tracのバージョンが違う!?
と言う事で/opt/python/2.5.2/lib/python2.5/site-packagesディレクトリで今日触ったものを調べると、

-rw-r--r--  1 root root      30  3月 28 10:45 setuptools.pth
-rw-r--r--  1 root root  333390  3月 28 10:45 setuptools-0.6c11-py2.5.egg
-rw-r--r--  1 root root   39322  3月 28 10:46 TracGit-0.12.0.5dev-py2.5.egg
-rw-r--r--  1 root root 1633391  3月 28 10:50 Trac-0.12.3-py2.5.egg
-rw-r--r--  1 root root     334  3月 28 10:51 easy-install.pth
-rw-r--r--  1 root root  261534  3月 28 10:51 Genshi-0.6-py2.5.egg

特に「TracGit-0.12.0.5dev-py2.5.egg」以降怪しそうなので、3つのeggファイルは別ディレクトリへ退避させてみた。
「easy-install.pth」は中身確認したら、この3つのファイルを参照してそうなので、その行を消してみることにした。
で、apacheを再起動したらめでたく復旧。

で、まとめー

  1. easy_installで何かインストールして怪しい動きするようになったら、対応するeggファイルを消してeasy-install.pthを編集すれば(きっと)元に戻せる
  2. ちゃんと本家のサイトを見よう。0.10.x系へのインストール方法は上述の方法では駄目なことは書いてあった
  3. そもそもちゃんとバージョン上げようぜ!