MoinMoin farming mode with apache2 and mod_wsgi

Why? Because MoinMoin is a widely used wiki, dyne.org uses MoinMoin and I thought to keep a page with a guide to install the latest moinmoin version at the time I'm writing 2024-03-28

Basic idea

The basic idea is that in farming mode each wiki has it's own instance. For its own instance we mean data, configuration files, stylesheets and plugins Search on the online documentation of moinmoin I found http://moinmo.in/FarmQuestions

/home/wiki/
    bin/
        moin.wsgi
    config/
        farmconfig.py   # contain the basic configurations common to all wikis
        mywiki.py       # site1
        rcyb.py         # site2
        logging/
            logfile.conf
    plugin/          # systemwide plugins
    underlay/        # read-only doc
        pages/   #<--- need to be rwx for owner and group www-data
    wikis/
        mywiki/
            data/    #<--- need to be rwx for owner and group www-data and so for
                plugin -> ../../../plugin
        rcyb/
            data/

All the static content will be in the DocRoot of the webserver (e.g. /var/www/$(wikiname|hostname)/htdocs

At the end each host in the farm could have something like http://wherewerehome.nn/wiki/$(wikiname|hostname)/ with a rewrite rule (I'm might be totally wrong and a rewrite rule might not be usefull but I'm thinking in case of migration from server to server) in case of dedicated hostname, e.g. http://groupxy.com/wiki that point to http://wherewerehome.nn/wiki/$groupxy/

The apache2 setup

First check that libapache2-mod_wsgi or similar is installed, check that is loaded by apache ( a2enmod wsgi && apachectl restart )

This is my sample virtual host for the sum off all the wikis:

NameVirtualHost nnn.nnn.nnn.nnn
<VirtualHost thefarm>
        ServerAdmin webmaster@thefarm
        ServerName thefarm

        DocumentRoot /var/www
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /var/www/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>
        
        #This is for FCKeditor and goes 1st cause is longer than the next alias (it doesn't work otherwise)
        Alias /moin_static/applets/FCKeditor/ "/usr/share/fckeditor/"

        # Static data, styleshets and images
        Alias /moin_static /var/www/wiki/htdocs

        #
        # WSGIScriptAlias /wiki /home/wiki/bin/moin.wsgi
        # match rules for multihoming, multihoming won't work without
        WSGIScriptAliasMatch ^/wiki/([^/]+) /home/wiki/bin/moin.wsgi

        # create some wsgi daemons - use someuser.somegroup same as your data_dir:
        WSGIDaemonProcess wiki user=wiki group=wiki home=/home/wiki processes=5 threads=10 maximum-requests=1000
        # umask=0007 does not work for mod_wsgi 1.0rc1, but will work later

        # use the daemons we defined above to process requests!
        WSGIProcessGroup wiki

        # this is here because I'm integrating moinmoin in various frameworks(RoR,django,phpcake) and I had to be sure that the wiki dir is handled only by moinmoin
        <Location /wiki>
                SetHandler None
        </Location>

        # this is for the basic
        <Location /moin_static>
                SetHandler None
        </Location>
        <Directory /var/www/moin/htdocs>
                Order allow,deny
                Allow from all
        </Directory>

        # this is for the multihoming
        # now don't need to restart apache when adding new wikis :)
        # could do the same trick to run custom moin.wsgi

        Alias /moin_([^/]+) /home/wiki/wikis/([^/]+)/htdocs
        <DirectoryMatch ^/home/wiki/wikis/([^/]+)/>
                Order deny,allow
                Allow from all
        </DirectoryMatch>

        ErrorLog /var/log/apache2/stargate1-error.log

        LogLevel warn

        CustomLog /var/log/apache2/stargate1-access.log combined

</VirtualHost>

The instance

I adjusted a script to arrange the wikis, it only add a wiki, it should make snapshots of data and config. Whould be possible to have the data in dated tarballs and configs via git.

--- not tested yet ---

This is createinstance.sh:

# path of MoinMoin shared files
BASE=/home/wiki/
WIKIS=$BASE/wikis

# path to target instance location
INSTANCE=$1

# should be nice
USER=www-data
GROUP=www-data

if [ ! $1 ]
then
  echo "You must specify an instance (relative or absolute path)"
  echo "You can also specify --withdocs to have a copy of moin docs in instance"
  exit
fi

if [[ -e $1 || -d $1 ]]
then
  echo "$1 already exists"
  exit
fi

mkdir -p $WIKIS/$INSTANCE
cp -va $BASE/data $WIKIS/$INSTANCE

if [ $2 = "--withdocs" ]; then
   cp -va $BASE/underlay $WIKIS/$INSTANCE
fi

cp -v $BASE/config/wikiconfig.py $BASE/config/$INSTANCE.py

chown -R $USER.$GROUP $WIKIS/$INSTANCE
chmod -R ug+rwX $WIKIS/$INSTANCE
chmod -R o-rwx $WIKIS/$INSTANCE

if [ $? ]
then
  echo "Done."
else
  echo "Something went wrong :P"
fi

This script could be extend also for backup/restore, move to remote farm, import from remote farm

MoinMoinFarmingApache2WSGI (last edited 2010-07-20 17:47:25 by anonymous)