]> sipb.mit.edu Git - ikiwiki.git/blob - doc/tips/distributed_wikis.mdwn
i still don't get it
[ikiwiki.git] / doc / tips / distributed_wikis.mdwn
1 [[rcs/git]] and other distributed version control systems are all about
2 making it easy to create and maintain copies and branches of a project. And
3 this can be used for all sorts of interesting stuff. Since ikiwiki can use
4 git, let's explore some possibilities for distributed wikis.
5
6 [[!toc levels=2]]
7
8 ## Overview
9
10 There are several possible level of decentralisation:
11
12  0. [[default setup|rcs/git]], no decentralisation
13  1. [[a simple HTML mirror|tips/Git_repository_and_web_server_on_different_hosts/]]
14  2. [[separate ikiwiki and git servers|tips/Hosting_Ikiwiki_and_master_git_repository_on_different_machines]]
15  3. separate `srcdir`, still requires a central bare repo - uses [[plugins/pinger]]
16  4. completely distinct ikiwiki installs, synchronised with [[plugins/contrib/gitpush]]
17
18 Here's a graphic overview of those:
19
20 ### Default setup - one central server
21
22 [[!img rcs/git/wiki_edit_flow.svg size=400x]]
23
24 In the default setup, all the resources are stored on the central
25 servers. Users can still clone and edit the git repo by hand and
26 contribute by git, but otherwise all the changes happen on a single
27 web interface. This basic setup is best described in [[rcs/git]].
28
29 ### Separate webserver and git repository
30
31 [[!img tips/Git_repository_and_web_server_on_different_hosts/separate-webserver.svg size=400x]]
32
33 This is the configuration described in
34 [[tips/Git_repository_and_web_server_on_different_hosts]]. The webserver part
35 hosts the HTML files, the ikiwiki [[cgi]] but everything else is on
36 the git server.
37
38 ### Separate ikiwiki web server, and git server
39
40 [[!img Hosting_Ikiwiki_and_master_git_repository_on_different_machines/separate-web-git-servers.svg size=400x]]
41 [[http://spalax.fr.eu.org/separate-web-git-servers.svg]] *Could someone with admin rights upload [[this image|http://spalax.fr.eu.org/separate-web-git-servers.svg]] to [[IkiWiki|Hosting_Ikiwiki_and_master_git_repository_on_different_machines/separate-web-git-servers.svg]]? I am not allowed to do so. [[Louis|spalax]]*
42
43 This is the configuration described in
44 [[tips/Hosting_Ikiwiki_and_master_git_repository_on_different_machines]]. One server hosts the web server (and the [[Ikiwiki cgi|cgi]]) and the git source dir; a second server hosts the git bare repository. This can be used when you have very limited access to the git server.
45
46 > I don't understand how this configuration is different from the previous one, could you clarify? the image link is broken as well. [[anarcat]]
47 >> Sorry. I did a mistake. I hope this is more clear now. [[Louis|spalax]]
48 >>> I still don't understand the difference, and I can't reach the URL you have given above. Previously, to upload stuff I created a clone of the git repository and asked joeyh to pull, like [[this|todo/improve_decentralised_wikis_documentation_and_graphics/]]. --[[anarcat]]
49  
50 ### Decentralised pinger setup
51
52 [[!img ping-setup.svg size=400x]]
53
54 In this configuration, the mirrors all have their own `srcdir`, but
55 still need to push and pull from the same central bare git repo. The
56 [[plugins/pinger]] plugin is used to ping the mirrors from the central
57 server on edits.
58
59 Step by step setup instructions for this are detailed below.
60
61 ### Fully decentralised setup
62
63 [[!img decentralized_wikis.svg size=400x]]
64
65 In this configuration, each wiki is fully independent and pushes its
66 changes to other wikis using the [[plugins/contrib/gitpush]] plugin.
67
68 ## Step by step setup instructions
69
70 The first two ways of setting up ikiwiki are better described in [[setup]] or [[tips/Git_repository_and_web_server_on_different_hosts]]. The remainder of this page describes the latter two more complex distributed setups. 
71
72 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.
73
74 Note that parts of the following documentation duplicate instructions from [[setup]], [[setup/byhand]], [[rcs/git]] and [[tips/laptop_wiki_with_git]].
75
76 ### Installing ikiwiki
77
78 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.
79
80     apt-get install ikiwiki
81
82 ### Setting up the wiki
83
84 (!) Optionnally: create a user just for this wiki. Otherwise the wiki will run as your user from here on.
85
86 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).
87
88     cd ~user
89     # setup srcdir, named source
90     git clone git://wiki.example.com/ source
91     # convenience copy of the setup file
92     git clone -b origin/setup source setup
93     cd setup
94     edit ikiwiki.setup # adapt configuration
95
96 When editing ikiwiki.setup, make sure you change the following entries:
97
98     cgiurl: http://mirror.example.com/ikiwiki.cgi
99     cgi_wrapper: /var/www/ikiwiki.cgi
100     srcdir: /home/user/source
101     destdir: /var/www/mirror.example.com
102     libdir: /home/user/source/.ikiwiki
103     git_wrapper: /home/user/source/.git/hooks/post-commit
104     git_test_receive_wrapper: /home/user/source/.git/hooks/pre-receive
105     ENV:
106       TMPDIR: /home/user/tmp
107
108 This assumes that your /var/www directory is writable by your user.
109
110 ### Basic HTML rendering
111
112 You should already be able to make a plain HTML rendering of the wiki:
113
114     ikiwiki --setup ikiwiki.setup
115
116 ### Webserver configuration
117
118 You will also need a webserver to serve the content in the `destdir`
119 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.
120
121 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, as ikiwiki will attempt to push to the central git repository at every change.
122
123 #### Apache configuration
124
125     <VirtualHost *:80>
126         ServerName mirror.example.com:80
127         DocumentRoot /var/www/mirror.example.com
128         <Directory /var/www/mirror.example.com>
129             Options Indexes MultiViews ExecCGI
130             AllowOverride None
131             Order allow,deny
132             allow from all
133         </Directory>
134         ScriptAlias /ikiwiki.cgi /var/www/ikiwiki.cgi
135         ErrorDocument 404 "/ikiwiki.cgi"
136     </VirtualHost>
137
138 #### Nginx configuration
139
140     server {
141         root /var/www/mirror.example.com/;
142         index index.html index.htm;
143         server_name mirror.example.com;
144
145         location / {
146             try_files $uri $uri/ /index.html;
147         }
148         location /ikiwiki.cgi {
149             fastcgi_pass  unix:/tmp/fcgi.socket;
150             fastcgi_index ikiwiki.cgi;
151             fastcgi_param SCRIPT_FILENAME   /var/www/ikiwiki.cgi;
152             fastcgi_param  DOCUMENT_ROOT      /var/www/mirror.example.com;
153             include /etc/nginx/fastcgi_params;
154         }
155     }
156
157 Start this process as your own user (or the user that has write access
158 to `srcdir`, `destdir`, etc):
159
160     spawn-fcgi -s /tmp/fcgi.socket -n -- /usr/sbin/fcgiwrap
161
162 Make this writable:
163
164     chmod a+w /tmp/fcgi.socket
165
166 ### Enable the pinger functionality
167
168 At this point, you need to enable the pinger functionality to make sure that changes on the central server propagate to your mirror.
169
170 This assumes a central wiki that exposes its git
171 repository and has the [[plugins/pinger]] plugin enabled. Enable the
172 [[plugins/pingee]] plugin in your configuration, and edit the origin wiki,
173 adding a ping directive for your mirror:
174
175         \[[!ping from="http://thewiki.com/"
176         to="http://mymirror.com/ikiwiki.cgi?do=ping"]]
177
178 The "from" parameter needs to be the url to the origin wiki. The "to" parameter
179 is the url to ping on your mirror. This can be done basically in any page.
180
181 Now whenever the main wiki is edited, it will ping your mirror, which will
182 pull the changes from "origin" using git, and update itself. It could, in
183 turn ping another mirror, etc.
184
185 And if someone edits a page on your mirror, it will "git push origin",
186 committing the changes back to the origin git repository, and updating the
187 origin mirror. Assuming you can push to that git repository. If you can't,
188 and you want a mirror, and not a branch, you should disable web edits on
189 your mirror. (You could also point the cgiurl for your mirror at the origin
190 wiki if you do not want to incur that overhead or do not want to, or can't, run a CGI.)
191
192 ### Fully decentralized configuration
193
194 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.
195
196 At the setup step, you need to create *two* git repositories on the mirror:
197
198     cd ~user
199     # setup base repository, named source.git
200     git clone --bare git://wiki.example.com/ source.git
201     # setup srcdir, named source
202     git clone source.git
203     # convenience copy of the setup file
204     git clone -b origin/setup source.git setup
205     cd setup
206     edit ikiwiki.setup # adapt configuration
207
208 The following entries will be different from the above setup file:
209
210     git_wrapper: /home/user/source.git/hooks/post-commit
211     git_test_receive_wrapper: /home/user/source.git/hooks/pre-receive
212
213 To do this, the mirror needs to push back to the master, using the [[plugins/contrib/gitpush]] plugin:
214
215     git_push_to:
216     - git://wiki.example.com/
217
218 This will ensure that commits done on the mirror will propagate back to the master.
219
220 ## Other ideas
221
222 See also:
223
224  * [[setup]]
225  * [[setup/byhand]]
226  * [[rcs/git]]
227  * [[tips/laptop_wiki_with_git]]
228  * [ikiwiki creation notes](http://piny.be/jrayhawk/notes/ikiwiki_creation/)
229
230 ### Announcing the mirror
231
232 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:
233
234     mirrorlist:
235       example: https://wiki.example.com/
236
237 The [[plugins/mirrorlist]] plugin of course needs to be enabled for this to work.
238
239 ### branching a wiki
240
241 It follows that setting up a branch of a wiki is just like the fully decentralised mirror above, except
242 we don't want it to push changes back to the origin. The easy way to
243 accomplish this is to clone the origin git repository using a readonly
244 protocol (ie, "git://"). Then you can't push to it.
245
246 If a page on your branch is modified and other modifications are made to
247 the same page in the origin, a conflict might occur when that change is
248 pulled in. How well will this be dealt with and how to resolve it? I think
249 that the conflict markers will just appear on the page as it's rendered in
250 the wiki, and if you could even resolve the conflict using the web
251 interface. Not 100% sure as I've not gotten into this situation yet.
252
253 --[[Joey]]