プレーンテキストなファイルで保存されるWikiでモダンなものがないかなーと思ったら
Gitをバックエンドに使ったプログラマ向きWiki - Gitit を見つけたので、Gititを Debian squeezeにインストールしてみた。
最初は記事の通り入れようと思ったんだけど、cabal installでエラーになり失敗。
検索してみると、
もしかしたらコンパイラが古いのではとGHCについて検索してみると、yumでインストールしたものは6.12.3で、http://www.haskell.org/ghc/ にある最新版は既に7.4.1になっていました。
さくらVPS(CentOS6)にGititをインストール
とのことなので、ビルドの依存パッケージを入れようとしたが、apt-cache searchしてたらgitit自体のパッケージがあることが判明。
# apt-get install gitでインストール完了。
# apt-get install gitit
あとは、
$ mkdir gititとすれば、とりあえず5001ポートで立ち上がるので、http://localhost:5001/で試すことができる。
$ cd gitit
$ gitit --print-default-config > gitit.conf
$ gitit -f gitit.conf
デフォルトでは、gitit/wikidataがレポジトリとなり、ページを作成すると、ページ名.pageというテキストファイルができる。ページの名前に/を入れてページを作れば、ディレクトリができる。日本語のページ名にすれば、日本語のファイル名ができる。UTF-8だったので、普通にlsで見れる。すごく幸せな感じ。
Webから変更するときに、変更内容を入力するが、これはコミットメッセージになる。
なお、フォーマットはデフォルトではMarkdown. reSTなどいくつかの形式に変更できる。
デーモン化
gititは(デフォルトでは?)フォアグラウンドで立ち上がるので、runitでデーモン化した。Debian的には、start-stop-daemonを使えばいいと思う。いつもの通り、適切な場所に"run"ファイルを作ってあげればおしまい。
(runsvdir対象ディレクトリは~/service, ログディレクトリは~/var/log/gititとする)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ mkdir -p ~/var/log/gitit | |
$ mkdir -p ~/service/.gitit/log | |
$ vi ~/service/.gitit/run | |
~~~ | |
#!/bin/sh | |
echo "Start." | |
cd ~/gitit | |
exec /usr/bin/gitit -f gitit.conf 2>&1 | |
~~~ | |
$ chmod +x ~/service/.gitit/run | |
$ vi ~/service/.gitit/log/run | |
~~~ | |
#!/bin/sh | |
exec svlogd -tt ~/var/log/gitit | |
~~~ | |
chmod +x ~/service/.gitit/log/run | |
$ mv ~/service/.gitit ~/service/gitit |
これでサービス化完了。
Apacheで受け付ける
Wiki自体に認証をかけたかったので、5001の前にApacheを立てる。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Location /> | |
AuthUserFile /srv/www/htpasswd-gitit | |
AuthGroupFile /dev/null | |
AuthName "Please enter username and password" | |
AuthType basic | |
require valid-user | |
</Location> | |
ProxyPass / http://127.0.0.1:5001/ | |
ProxyPassReverse / http://127.0.0.1:5001/ |
リンクに含まれるパスを調整する方法がわからなく、mod_proxy_htmlを使うのもなんだったので、VirtualHostで作った。適当なVirtualHostの設定を/etc/apache2/sites-available以下に置いて、a2ensiteで有効化した。
BASIC認証のユーザを使う
デフォルトではGititは自前のフォームで認証するため、BASIC認証とかぶってしまう。そのため、gigit.confを変更して、Apache側で認証したユーザ名を使えるようにする。~~~
authentication-method: http #formから変更~~~
ついでにトップページのファイル名もFront PageからFrontPageに変えてしまった。
~~~
front-page: FrontPage~~~
no-delete: FrontPage, Help
これで完了。