1 [[!meta date="2008-05-06 19:22:09 -0400"]]
3 [[rcs/git]] and other distributed version control systems are all about
4 making it easy to create and maintain copies and branches of a project. And
5 this can be used for all sorts of interesting stuff. Since ikiwiki can use
6 git, let's explore some possibilities for distributed wikis.
12 There are several possible level of decentralisation:
14 0. [[default setup|rcs/git]], no decentralisation
15 1. [[a simple HTML mirror|tips/Git_repository_and_web_server_on_different_hosts/]]
16 2. [[separate ikiwiki and git servers|tips/Hosting_Ikiwiki_and_master_git_repository_on_different_machines]]
17 3. separate `srcdir`, still requires a central bare repo - uses [[plugins/pinger]]
18 4. completely distinct ikiwiki installs
20 Here's a graphic overview of those:
22 ### Default setup - one central server
24 [[!img rcs/git/wiki_edit_flow.svg size=400x]]
26 In the default setup, all the resources are stored on the central
27 servers. Users can still clone and edit the git repo by hand and
28 contribute by git, but otherwise all the changes happen on a single
29 web interface. This basic setup is best described in [[rcs/git]].
31 ### Separate webserver and git repository
33 [[!img tips/Git_repository_and_web_server_on_different_hosts/separate-webserver.svg size=400x]]
35 This is the configuration described in
36 [[tips/Git_repository_and_web_server_on_different_hosts]]. The webserver part
37 hosts the HTML files, the ikiwiki [[cgi]] but everything else is on
40 ### Separate webserver and git repository, the git srcdir being hosted on the webserver
42 [[!img Hosting_Ikiwiki_and_master_git_repository_on_different_machines/separate-web-git-servers.svg size=400x]]
44 This is the configuration described in
45 [[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.
47 ### Decentralised pinger setup
49 [[!img ping-setup.svg size=400x]]
51 In this configuration, the mirrors all have their own `srcdir`, but
52 still need to push and pull from the same central bare git repo. The
53 [[plugins/pinger]] plugin is used to ping the mirrors from the central
56 Step by step setup instructions for this are detailed below.
58 ### Fully decentralised setup
60 [[!img decentralized_wikis.svg size=400x]]
62 In this configuration, each wiki is fully independent and pushes its
63 changes to other wikis using git.
65 ## Step by step setup instructions
67 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.
69 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.
71 Note that parts of the following documentation duplicate instructions from [[setup]], [[setup/byhand]], [[rcs/git]] and [[tips/laptop_wiki_with_git]].
73 ### Installing ikiwiki
75 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.
77 apt-get install ikiwiki
79 ### Setting up the wiki
81 (!) Optionnally: create a user just for this wiki. Otherwise the wiki will run as your user from here on.
83 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).
86 # setup srcdir, named source
87 git clone git://wiki.example.com/ source
88 # convenience copy of the setup file
89 git clone -b origin/setup source setup
91 edit ikiwiki.setup # adapt configuration
93 When editing ikiwiki.setup, make sure you change the following entries:
95 cgiurl: http://mirror.example.com/ikiwiki.cgi
96 cgi_wrapper: /var/www/ikiwiki.cgi
97 srcdir: /home/user/source
98 destdir: /var/www/mirror.example.com
99 libdir: /home/user/source/.ikiwiki
100 git_wrapper: /home/user/source/.git/hooks/post-commit
101 git_test_receive_wrapper: /home/user/source/.git/hooks/pre-receive
103 TMPDIR: /home/user/tmp
105 This assumes that your /var/www directory is writable by your user.
107 ### Basic HTML rendering
109 You should already be able to make a plain HTML rendering of the wiki:
111 ikiwiki --setup ikiwiki.setup
113 ### Webserver configuration
115 You will also need a webserver to serve the content in the `destdir`
116 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.
118 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.
120 #### Apache configuration
123 ServerName mirror.example.com:80
124 DocumentRoot /var/www/mirror.example.com
125 <Directory /var/www/mirror.example.com>
126 Options Indexes MultiViews ExecCGI
131 ScriptAlias /ikiwiki.cgi /var/www/ikiwiki.cgi
132 ErrorDocument 404 "/ikiwiki.cgi"
135 #### Nginx configuration
138 root /var/www/mirror.example.com/;
139 index index.html index.htm;
140 server_name mirror.example.com;
143 try_files $uri $uri/ /index.html;
145 location /ikiwiki.cgi {
146 fastcgi_pass unix:/tmp/fcgi.socket;
147 fastcgi_index ikiwiki.cgi;
148 fastcgi_param SCRIPT_FILENAME /var/www/ikiwiki.cgi;
149 fastcgi_param DOCUMENT_ROOT /var/www/mirror.example.com;
150 include /etc/nginx/fastcgi_params;
154 Start this process as your own user (or the user that has write access
155 to `srcdir`, `destdir`, etc):
157 spawn-fcgi -s /tmp/fcgi.socket -n -- /usr/sbin/fcgiwrap
161 chmod a+w /tmp/fcgi.socket
163 ### Enable the pinger functionality
165 At this point, you need to enable the pinger functionality to make sure that changes on the central server propagate to your mirror.
167 This assumes a central wiki that exposes its git
168 repository and has the [[plugins/pinger]] plugin enabled. Enable the
169 [[plugins/pingee]] plugin in your configuration, and edit the origin wiki,
170 adding a ping directive for your mirror:
172 \[[!ping from="http://thewiki.com/"
173 to="http://mymirror.com/ikiwiki.cgi?do=ping"]]
175 The "from" parameter needs to be the url to the origin wiki. The "to" parameter
176 is the url to ping on your mirror. This can be done basically in any page.
178 Now whenever the main wiki is edited, it will ping your mirror, which will
179 pull the changes from "origin" using git, and update itself. It could, in
180 turn ping another mirror, etc.
182 And if someone edits a page on your mirror, it will "git push origin",
183 committing the changes back to the origin git repository, and updating the
184 origin mirror. Assuming you can push to that git repository. If you can't,
185 and you want a mirror, and not a branch, you should disable web edits on
186 your mirror. (You could also point the cgiurl for your mirror at the origin
187 wiki if you do not want to incur that overhead or do not want to, or can't, run a CGI.)
189 ### Fully decentralized configuration
191 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.
193 At the setup step, you need to create *two* git repositories on the mirror:
196 # setup base repository, named source.git
197 git clone --bare git://wiki.example.com/ source.git
198 # setup srcdir, named source
200 # convenience copy of the setup file
201 git clone -b origin/setup source.git setup
203 edit ikiwiki.setup # adapt configuration
205 The following entries will be different from the above setup file:
207 git_wrapper: /home/user/source.git/hooks/post-commit
208 git_test_receive_wrapper: /home/user/source.git/hooks/pre-receive
210 To make the mirror push back to the master, use, for example:
212 git_wrapper_background_command: git push git://wiki.example.com/
214 This will help ensure that commits done on the mirror will propagate back to the master.
223 * [[tips/laptop_wiki_with_git]]
224 * [ikiwiki creation notes](http://piny.be/jrayhawk/notes/ikiwiki_creation/)
226 ### Announcing the mirror
228 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:
231 example: https://wiki.example.com/
233 The [[plugins/mirrorlist]] plugin of course needs to be enabled for this to work.
237 It follows that setting up a branch of a wiki is just like the fully decentralised mirror above, except
238 we don't want it to push changes back to the origin. The easy way to
239 accomplish this is to clone the origin git repository using a readonly
240 protocol (ie, "git://"). Then you can't push to it.
242 If a page on your branch is modified and other modifications are made to
243 the same page in the origin, a conflict might occur when that change is
244 pulled in. How well will this be dealt with and how to resolve it? I think
245 that the conflict markers will just appear on the page as it's rendered in
246 the wiki, and if you could even resolve the conflict using the web
247 interface. Not 100% sure as I've not gotten into this situation yet.