aboutsummaryrefslogtreecommitdiff
path: root/doc/tips/distributed_wikis.mdwn
blob: 4e084b25672cc489aff6b4527b215161cbd60773 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
[[rcs/git]] and other distributed version control systems are all about
making it easy to create and maintain copies and branches of a project. And
this can be used for all sorts of interesting stuff. Since ikiwiki can use
git, let's explore some possibilities for distributed wikis.

[[!toc levels=2]]

## Overview

There are three possible level of decentralisation:

 0. [[default setup|rcs/git]], no decentralisation
 1. [[a simple HTML mirror|tips/Git_repository_and_web_server_on_different_hosts/]]
 2. separate `srcdir`, still requires a central bare repo - uses [[plugin/pinger]]
 3. completely distinct ikiwiki installs, synchronised with
    [[plugin/gitpush]]

Here's a graphic overview of those:

### Default setup - one central server

[[!img rcs/git/wiki-edit-flow.svg size=490x align=center]]

In the default setup, all the resources are stored on the central
servers. Users can still clone and edit the git repo by hand and
contribute by git, but otherwise all the changes happen on a single
web interface.

### Separate webserver and git repository

[[!img tips/Git_repository_and_web_server_on_different_hosts/separate-webserver.svg align=center]]

In the configuration described in
[[tips/Git_repository_and_web_server_on_different_hosts]], the
webserver is separate from the git repository. The webserver part
hosts the HTML files, the ikiwiki [[cgi]] but everything else is on
the git server.

### Decentralised pinger setup

[[!img ping-setup.svg align=center]]

In this configuration, the mirrors all have their own `srcdir`, but
still need to push and pull from the same central bare git repo. The
[[plugins/pinger]] plugin is used to ping the mirrors from the central
server on edits.

### Fully decentralised setup

[[!img .svg align=center]]

In this configuration, each wiki is fully independent and pushes its
changes to other wikis using the [[plugins/gitpush]] plugin.

## a wiki mirror

The simplest possibility is setting up a mirror. If a wiki exposes its git
repository and has the [[plugins/pinger]] plugin enabled, then anyone can
set up a mirror that will automatically be kept up-to-date with the origin
wiki. Just clone the git repo, configure ikiwiki to use it, enable the
[[plugins/pingee]] plugin in your configuration, and edit the origin wiki,
adding a ping directive for your mirror:

	\[[!ping from="http://thewiki.com/"
	to="http://mymirror.com/ikiwiki.cgi?do=ping"]]

The "from" parameter needs to be the url to the origin wiki. The "to" parameter
is the url to ping on your mirror.

Now whenever the main wiki is edited, it will ping your mirror, which will
pull the changes from "origin" using git, and update itself. It could, in
turn ping another mirror, etc.

And if someone edits a page on your mirror, it will "git push origin",
committing the changes back to the origin git repository, and updating the
origin mirror. Assuming you can push to that git repository. If you can't,
and you want a mirror, and not a branch, you should disable web edits on
your mirror. (You could also point the cgiurl for your mirror at the origin
wiki.)

## branching a wiki

It follows that setting up a branch of a wiki is just like a mirror, except
we don't want it to push changes back to the origin. The easy way to
accomplish this is to clone the origin git repository using a readonly
protocol (ie, "git://"). Then you can't push to it.

If a page on your branch is modified and other modifications are made to
the same page in the origin, a conflict might occur when that change is
pulled in. How well will this be dealt with and how to resolve it? I think
that the conflict markers will just appear on the page as it's rendered in
the wiki, and if you could even resolve the conflict using the web
interface. Not 100% sure as I've not gotten into this situation yet.

--[[Joey]]

## Practical example

Say you have a friend that has already configured a shiny ikiwiki site, and you want to help by creating a mirror. You still need to figure out how to install ikiwiki and everything, hopefully this section will help you with that.

### Installing ikiwiki

You need to install the ikiwiki package for the mirror to work. You can use ikiwiki to publish the actual HTML pages elsewhere if you don't plan on letting people edit the wiki, but generally you want the package to be installed on the webserver for editing to work.

    apt-get install ikiwiki

### Setting up the wiki

(!) Optionnally: create a user just for this wiki. Otherwise the wiki will run as your user from here on.

We assume your username is `user` and that you will host the wiki under the hostname `mirror.example.com`. The original wiki is at `wiki.example.com`. We also assume that your friend was nice enough to provide a copy of the `.setup` file in the `setup` branch, which is the case for any wiki hosted on [branchable.com](http://branchable.com).

    cd ~user
    # setup srcdir, named source
    git clone git://wiki.example.com/ source
    # convenience copy of the setup file
    git clone -b origin/setup source setup
    cd setup
    edit ikiwiki.setup # adapt configuration

When editing ikiwiki.setup, make sure you change the following entries:

    cgiurl: http://mirror.example.com/ikiwiki.cgi
    cgi_wrapper: /var/www/ikiwiki.cgi
    srcdir: /home/user/source
    destdir: /var/www/mirror.example.com
    libdir: /home/user/source/.ikiwiki
    git_wrapper: /home/user/source/.git/hooks/post-commit
    git_test_receive_wrapper: /home/user/source/.git/hooks/pre-receive
    ENV:
      TMPDIR: /home/user/tmp

This assumes that your /var/www directory is writable by your user.

### Basic HTML rendering

You should already be able to make a plain HTML rendering of the wiki:

    ikiwiki --setup ikiwiki.setup

### Webserver configuration

You will also need a webserver to serve the content in the `destdir`
defined above. We assume you will configure a virtual host named `mirror.example.com`. Here are some examples on how to do those, see [[!iki setup]] and [[!iki tips/dot_cgi]] for complete documentation.

Note that this will also configure CGI so that people can edit the wiki. Note that this configuration may involve timeouts if the main site is down.

#### Apache configuration

    <VirtualHost *:80>
        ServerName mirror.example.com:80
        DocumentRoot /var/www/mirror.example.com
        <Directory /var/www/mirror.example.com>
            Options Indexes MultiViews ExecCGI
            AllowOverride None
            Order allow,deny
            allow from all
        </Directory>
        ScriptAlias /ikiwiki.cgi /var/www/ikiwiki.cgi
        ErrorDocument 404 "/ikiwiki.cgi"
    </VirtualHost>

#### Nginx configuration

    server {
        root /var/www/mirror.example.com/;
        index index.html index.htm;
        server_name mirror.example.com;

        location / {
            try_files $uri $uri/ /index.html;
        }
        location /ikiwiki.cgi {
            fastcgi_pass  unix:/tmp/fcgi.socket;
            fastcgi_index ikiwiki.cgi;
            fastcgi_param SCRIPT_FILENAME   /var/www/ikiwiki.cgi;
            fastcgi_param  DOCUMENT_ROOT      /var/www/mirror.example.com;
            include /etc/nginx/fastcgi_params;
        }
    }

Start this process as your own user (or the user that has write access
to `srcdir`, `destdir`, etc):

    spawn-fcgi -s /tmp/fcgi.socket -n -- /usr/sbin/fcgiwrap

Make this writable:

    chmod a+w /tmp/fcgi.socket

### Read-only mirror: done!

At this point, you are done! You can edit your own clone of the wiki, although your changes will not go back to the main site. However, you can always push or pull manually from the `repository` in `~user/source.git` to update the main site.

### Announcing the mirror

Once your mirror works, you can also add it to the list of mirrors. You can ask the mirror where you take it from (and why not, all mirrors) to add it to their setup file. As an example, here's the configuration for the first mirror:

    mirrorlist:
      example: https://wiki.example.com/

The [[plugins/mirrorlist]] plugin of course needs to be enabled for this to work.

### Alternative configuration

In the above configuration, the master git repository is still on the main site. If that site goes down, there will be delays when editing the wiki mirror. It could also simply fail because it will not be able to push the changes to the master git repo. An alternative is to setup a local bare repository that is synced with the master.

At the setup step, you need to create *two* git repositories on the mirror:

    cd ~user
    # setup base repository, named source.git
    git clone --bare git://wiki.example.com/ source.git
    # setup srcdir, named source
    git clone source.git
    # convenience copy of the setup file
    git clone -b origin/setup source.git setup
    cd setup
    edit ikiwiki.setup # adapt configuration

The following entries will be different from the above setup file:

    git_wrapper: /home/user/source.git/hooks/post-commit
    git_test_receive_wrapper: /home/user/source.git/hooks/pre-receive

To do this, the mirror needs to push back to the master, again using the gitpush plugin:

    git_push_to:
    - git://wiki.example.com/

This will ensure that commits done on the mirror will propagate back to the master.

### Other guides

Another guide is the [[tips/laptop_wiki_with_git]] guide. To get a
better understanding of how ikiwiki works, see [[rcs/git]].

[This](http://piny.be/jrayhawk/notes/ikiwiki_creation/) may also be of
use if the above doesn't work.