さくらスタンダードに MoinMoin 1.8.7 の wikifarm をインストール

さくらスタンダードに MoinMoin 1.8.7 を wikifarm 設定でインストールします。まずは自分専用の Wiki を作ることを想定 *1 。とりあえず動くところまで。

今回の想定。

この例を作る際の作業では virtual-python.py でホームディレクトリに移植した実行環境を使用。

詳しくは上記サイトを参考にしてもらうとして、今回の環境は

% /usr/local/bin/python virtual-python.py --prefix=$HOME/local

を実行してあり、PATH と PYTHONPATH を通してます。以下 .cshrc 参考。

setenv PATH        $HOME/local/bin:$PATH
setenv PYTHONPATH  $HOME/local/lib/python
setenv PYTHONPATH  ${PYTHONPATH}:$HOME/local/lib/python/site-packages

$HOME/local/lib/python は $HOME/local/lib/python2.6 へのシンボリックリンクになってます。

最終的なディレクトリ構成はこんなかんじ。

/home/foobar/
    .moin/
        foobar/
            data/ <--------- データディレクトリ
        wikifarm/ <--------- 設定ファイル置き場
    local/
        src/ <-------------- 作業ディレクトリ
        share/
            moin/ <--------- 設置に必要なファイルがインストールされる
    www/
        example.net/ <------ example.netのDocumentRoot
            moin/
                moin.cgi <-- MoinMoinの実行ファイル
                static/ <--- 静的ファイル(css, js etc.)


ディレクトリ作成からダウンロード、展開まで。説明のため何てことない作業にも -v (verbose) オプション。

~% mkdir -pv ~/local/src
local
local/src
~% cd -v local/src  # 作業ディレクトリへ
0       ~/local/src
~/local/src% wget http://static.moinmo.in/files/moin-1.8.7.tar.gz
(...)
2010-04-17 15:43:21 (496 KB/s) - `moin-1.8.7.tar.gz' saved [6698609/6698609]

~/local/src% tar xvf moin-1.8.7.tar.gz  # 展開
(...)
x moin-1.8.7/setup.cfg
x moin-1.8.7/setup.py
~/local/src% 

ビルド、dry-run、インストール。面倒ならいきなり install でも OK。 --record=/path/to/logfile という形式でインストールログ。

~/local/src$ cd -v moin-1.8.7  # 展開されたディレクトリへ
0       ~/local/src/moin-1.8.7
~/local/src/moin-1.8.7% python setup.py build  # ビルド
(...)
running build_scripts
creating build/scripts-2.6
~/local/src/moin-1.8.7% python setup.py -n install --prefix=$HOME/local --record=install.log  # dry-run
running install
running build
running build_py
running build_scripts
running install_lib
running install_scripts
copying build/scripts-2.6/moin -> /home/foobar/local/bin
changing mode of /home/foobar/local/bin/moin
running install_data
running install_egg_info
Removing /home/foobar/local/lib/python/site-packages/moin-1.8.7-py2.6.egg-info
Writing /home/foobar/local/lib/python/site-packages/moin-1.8.7-py2.6.egg-info
~/local/src/moin-1.8.7% python setup.py install --prefix=$HOME/local --record=install.log  # 本番

本番出力は -n と同じなので割愛。どこに何があるかは cat install.log | grep hoge とかで。

以下 wikifarm の設定。

~/local/src/moin-1.8.7% cd
~% mkdir -v ~/.moin  # 設定を置くディレクトリ作成
/home/foobar/.moin
~% cp -Rav ~/local/share/moin/config/wikifarm/ ~/.moin/
/home/foobar/local/share/moin/config/wikifarm/ -> /home/foobar/.moin
/home/foobar/local/share/moin/config/wikifarm/farmconfig.py -> /home/foobar/.moin/farmconfig.py
/home/foobar/local/share/moin/config/wikifarm/mywiki.py -> /home/foobar/.moin/mywiki.py
~% cp -Rav ~/local/share/moin/data ~/.moin
(...)
~% cd ~/.moin/wikifarm  # wikifarm設定ディレクトリへ
~/.moin/wikifarm% ls
farmconfig.py   mywiki.py
~/.moin/wikifarm% vi farmconfig.py  # farm設定ファイル編集

farmconfig.py の diff

~/.moin/wikifarm% diff -U2 farmconfig.py farmconfig.py.modified
--- farmconfig.py             2010-02-15 06:56:22.000000000 +0900
+++ farmconfig.py.modified    2010-04-17 15:55:55.000000000 +0900
@@ -1,3 +1,3 @@
-# -*- coding: iso-8859-1 -*-
+# -*- coding: utf-8 -*-
 # IMPORTANT! This encoding (charset) setting MUST be correct! If you live in a
 # western country and you don't know that you use utf-8, you probably want to
@@ -46,9 +46,10 @@
     # wikiname,     url regular expression (no protocol)
     # ---------------------------------------------------------------
-    ("mywiki", r".*"),   # this is ok for a single wiki
+    #("mywiki", r".*"),   # this is ok for a single wiki

     # for multiple wikis, do something like this:
     #("moinmoin",    r"^moinmo.in/.*$"),
     #("moinmaster",  r"^master.moinmo.in/.*$"),
+    ("foobar",  r"^example.net/moin/.*$"),
 ]

@@ -83,5 +84,5 @@
     # Where your mutable wiki pages are. You want to make regular
     # backups of this directory.
-    data_dir = './data/'
+    data_dir = '/home/foobar/.moin/foobar/data/'

     # Where read-only system and help page are. You might want to share
@@ -90,5 +91,5 @@
     # directory is part of MoinMoin distribution, you don't have to
     # backup it.
-    data_underlay_dir = './underlay/'
+    data_underlay_dir = '/home/foobar/local/share/moin/underlay/'

     # The URL prefix we use to access the static stuff (img, css, js).
@@ -106,14 +107,15 @@
     # This is checked by some rather critical and potentially harmful actions,
     # like despam or PackageInstaller action:
-    #superuser = [u"YourName", ]
+    superuser = [u"FooBar", ]

     # IMPORTANT: grant yourself admin rights! replace YourName with
     # your user name. See HelpOnAccessControlLists for more help.
     # All acl_rights_xxx options must use unicode [Unicode]
-    #acl_rights_before = u"YourName:read,write,delete,revert,admin"
+    acl_rights_before = u"FooBar:read,write,delete,revert,admin All:read,write"

     # Link spam protection for public wikis (uncomment to enable).
     # Needs a reliable internet connection.
-    #from MoinMoin.security.antispam import SecurityPolicy
+    from MoinMoin.security.antispam import SecurityPolicy


@@ -159,5 +161,5 @@

     # The main wiki language, set the direction of the wiki pages
-    language_default = 'en'
+    language_default = 'ja'

     # the following regexes should match the complete name when used in free text

Wikifarm 全体のレベルで All のデフォルトは read と write の両権限を持たせている。

iso-8859-1 を utf-8 にしてるとこはこのファイル内で日本語を使いたい場合に必要だけど、その場合はきちんと utf-8 で保存すること。変えなくても Wiki そのもののデフォルトは utf-8 になってる。

mywiki.py をコピーして foobar.py を作る。

~/.moin/wikifarm% cp -v mywiki.py foobar.py  # パッケージ付属のwiki設定ファイルを複製
mywiki.py -> foobar.py
~/.moin/wikifarm% mv -v mywiki.py mywiki.py.sample  # 付属ファイルは無効にしておく
mywiki.py -> mywiki.py.sample
~/.moin/wikifarm% vi foobar.py  # 設定ファイル編集

foobar.py の diff

~/.moin/wikifarm% diff -U2 foobar.py foobar.py.modified
--- foobar.py             2010-02-15 06:56:22.000000000 +0900
+++ foobar.py.modified    2010-04-17 15:55:55.000000000 +0900
@@ -1,3 +1,3 @@
-# -*- coding: iso-8859-1 -*-
+# -*- coding: utf-8 -*-
 # IMPORTANT! This encoding (charset) setting MUST be correct! If you live in a
 # western country and you don't know that you use utf-8, you probably want to
@@ -20,6 +20,6 @@

     # basic options (you normally need to change these)
-    sitename = u'MyWiki' # [Unicode]
-    interwikiname = u'MyWiki' # [Unicode]
+    sitename = u'FooBar' # [Unicode]
+    interwikiname = u'FooBar' # [Unicode]

     # name of entry page / front page [Unicode], choose one of those:
@@ -31,4 +31,6 @@
     page_front_page = u"FrontPage"

-    data_dir = '/org/mywiki/data/'
+    data_dir = '/home/foobar/.moinmoin/foobar/data/'
+    url_prefix_static = '/moin/static'
+    acl_rights_default = FarmConfig.acl_rights_default + u'All:read'

ここで All の権限を read に限定。

wikifarm での設定クラスは

DefaultConfig ← FarmConfig (farmconfig.py内) ← Config (foobar.py内)

という継承関係になってるので、ある Farm に属する Wiki (たち)のデフォルトを決めるのが farmconfig.py 、個別 Wiki の設定を foobar.py (など)で上書きする*2

で、外から見える場所に実行ファイルを置く。

~% # インストールディレクトリからCGI実行ファイルをコピー
~% cp -v ~/local/share/moin/server/moin.cgi ~/www/example.net/moin
/home/foobar/local/share/moin/server/moin.cgi -> /home/foobar/www/example.net/moin/moin.cgi
~% vi ~/www/example.net/moin/moin.cgi  # 実行ファイルを編集

moin.cgi の diff

--- moin.cgi             2010-02-15 06:56:40.000000000 +0900
+++ moin.cgi.modified    2010-04-17 15:55:55.000000000 +0900
@@ -1,5 +1,5 @@
-#!/usr/bin/env python
-# -*- coding: iso-8859-1 -*-
+#!/home/foobar/local/bin/python
+# -*- coding: utf-8 -*-
 """
     MoinMoin - CGI Driver Script

@@ -17,11 +17,13 @@
 # a1) Path of the directory where the MoinMoin code package is located.
 #     Needed if you installed with --prefix=PREFIX or you didn't use setup.py.
 #sys.path.insert(0, 'PREFIX/lib/python2.3/site-packages')
+sys.path.insert(0, '/home/foobar/local/lib/python/site-packages')

 # a2) Path of the directory where wikiconfig.py / farmconfig.py is located.
 #     See wiki/config/... for some sample config files.
 #sys.path.insert(0, '/path/to/wikiconfigdir')
 #sys.path.insert(0, '/path/to/farmconfigdir')
+sys.path.insert(0, '/home/foobar/.moin/wikifarm')

 # b) Configuration of moin's logging
 #    If you have set up MOINLOGGINGCONF environment variable, you don't need this!
@@ -38,7 +40,7 @@

 class Config(CgiConfig):
     # Server name - used to create .prof files
-    name = 'moin'
+    name = 'foobar'

     # Properties
     # Allow overriding any request property by the value defined in

シンボリックリンクがなくて動かなければ

sys.path.insert(0, '/home/foobar/local/lib/python2.6/site-packages')

と書く。ともあれパーミッション変更。

~% chmod 700 ~/www/example.net/moin/moin.cgi

ここまでやって example.net/moin/moin.cgi を開いて Wiki らしきページが表示されたら、とりあえず動いてる。

で、まだ CSS 等々が効いてないので静的ファイルをコピー or 面倒ならシンボリックリンクで済ませる。Wikifarm に属する Wiki ごとに faviconrobots.txt をいじれることもあり、コピーのほうがおすすめ。

~% cp -ra ~/local/share/moin/htdocs ~/www/example.net/moin/static
~% ln -sv ~/local/share/moin/htdocs/ ~/www/example.net/moin/static
/home/foobar/www/run4it.org/foobar/static -> /home/foobar/local/share/moin/htdocs/

きちんとテーマが反映されたら、さきほど設定したスーパーユーザ(この例では FooBar)でユーザを作成。無事できたら example.net/moin/SystemPagesSetup で翻訳パックとかをインストールしてもいいかも。

example.net/moin/FrontPage というURLでアクセスできるよう moin.cgi と .htaccess を設定。

~% cd www/example.net/moin
~/www/example.net/moin% vi moin.cgi
   # Properties
   # Allow overriding any request property by the value defined in
   # this dict e.g properties = {'script_name': '/mywiki'}.
   ## properties = {}
   properties = {'script_name':'/moin'}
~/www/example.net/moin% vi .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /foobar/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /foobar/moin.cgi/$1 [L,QSA]
</IfModule>

今回は自分専用にしたいので、下のURLを参考に、自由にユーザを作成できないようにする。これをやると以後一切(コメントアウトしない限り)作成できないので、ユーザを作ってから有効にする。

farmconfig.py (Farm全体)か foobar.py (個別Wiki)に以下を追記。

# stop new accounts being created
actions_excluded = ['newaccount']

ログファイルの設定。ただ動けばいいなら設定の必要はない(ページ更新履歴はデータディレクトリに記録される)。

~% cp -Ra ~/local/share/moin/logging ~/.moin/  # ログ設定ディレクトリコピー
~% cp -a ~/.moin/logging/logfile ~/.moin/logging/logfile-foobar  # ログ設定をコピー
~% mkdir ~/.moin/log  # ログ保存ディレクトリ作成
~% vi ~/.moin/logging/logfile-foobar  # ログ設定を編集

設定ファイル冒頭にログファイルのパスを書く。

# Logfile to create.
# Make sure the running moin process has create/write rights there.
#logfile=/tmp/moin.log
logfile=/home/foobar/.moin/log/foobar.log

moin.cgi にログ設定ファイルのパスを書く。

# b) Configuration of moin's logging
#    If you have set up MOINLOGGINGCONF environment variable, you don't need this!
#    You also don't need this if you are happy with the builtin defaults.
#    See wiki/config/logging/... for some sample config files.
#from MoinMoin import log
#log.load_config('/path/to/logging_configuration_file')
from MoinMoin import log
log.load_config('/home/foobar/.moin/logging/logfile-foobar')

参考サイト

ありがとうございました。

ではここらでドロン。

追記(2010/04/18)
farmconfig.py と foobar.py の権限設定を追記(「自分専用」になってなかった)、ついでにログファイルの設定。
追記(2010/04/19)
CGI実行ファイルのコピー先が間違っていたのを訂正。ついでにコメントを少し追加。
追記(2010/11/04)
farmconfig.py の acl_rights_before 部分で管理権限が与えられていなかった部分を修正。 diff の行数ずれてるけど放置。

*1:もちろん、他人に公開しなくていいならローカルで使うべきだし、設置の手間も少ない。Windows しかなくても [http://www.apachefriends.org/jp/xampp-windows.html:title=XAMPP] + [http://code.google.com/p/modwsgi/:title=mod_wsgi] で構成できて、さくらに設置するより簡単です。

*2:根本でいじりたかったら local/lib/python/site-packages/MoinMoin/config/__init__.py を見たらいいんじゃないかな。