]> sipb.mit.edu Git - ikiwiki.git/blob - doc/tips/distributed_wikis.mdwn
add a practical example on how to do a mirror
[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 ## a wiki mirror
7
8 The simplest possibility is setting up a mirror. If a wiki exposes its git
9 repository and has the [[plugins/pinger]] plugin enabled, then anyone can
10 set up a mirror that will automatically be kept up-to-date with the origin
11 wiki. Just clone the git repo, configure ikiwiki to use it, enable the
12 [[plugins/pingee]] plugin in your configuration, and edit the origin wiki,
13 adding a ping directive for your mirror:
14
15         \[[!ping from="http://thewiki.com/"
16         to="http://mymirror.com/ikiwiki.cgi?do=ping"]]
17
18 The "from" parameter needs to be the url to the origin wiki. The "to" parameter
19 is the url to ping on your mirror.
20
21 Now whenever the main wiki is edited, it will ping your mirror, which will
22 pull the changes from "origin" using git, and update itself. It could, in
23 turn ping another mirror, etc.
24
25 And if someone edits a page on your mirror, it will "git push origin",
26 committing the changes back to the origin git repository, and updating the
27 origin mirror. Assuming you can push to that git repository. If you can't,
28 and you want a mirror, and not a branch, you should disable web edits on
29 your mirror. (You could also point the cgiurl for your mirror at the origin
30 wiki.)
31
32 ## branching a wiki
33
34 It follows that setting up a branch of a wiki is just like a mirror, except
35 we don't want it to push changes back to the origin. The easy way to
36 accomplish this is to clone the origin git repository using a readonly
37 protocol (ie, "git://"). Then you can't push to it.
38
39 If a page on your branch is modified and other modifications are made to
40 the same page in the origin, a conflict might occur when that change is
41 pulled in. How well will this be dealt with and how to resolve it? I think
42 that the conflict markers will just appear on the page as it's rendered in
43 the wiki, and if you could even resolve the conflict using the web
44 interface. Not 100% sure as I've not gotten into this situation yet.
45
46 --[[Joey]]
47
48 ## Practical example
49
50 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.
51
52 ### Installing ikiwiki
53
54 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.
55
56     apt-get install ikiwiki
57
58 ### Setting up the wiki
59
60 (!) Optionnally: create a user just for this wiki. Otherwise the wiki will run as your user from here on.
61
62 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).
63
64     cd ~user
65     # setup base repository, named source.git
66     git clone --bare git://wiki.example.com/ source.git
67     # setup srcdir, named source
68     git clone source.git
69     # convenience copy of the setup file
70     git clone -b origin/setup source.git setup
71     cd setup
72     edit ikiwiki.setup # adapt configuration
73
74 When editing ikiwiki.setup, make sure you change the following entries:
75
76     cgiurl: http://mirror.example.com/ikiwiki.cgi
77     cgi_wrapper: /var/www/ikiwiki.cgi
78     srcdir: /home/user/source
79     destdir: /var/www/mirror.example.com
80     libdir: /home/user/source/.ikiwiki
81     git_wrapper: /home/user/source.git/hooks/post-commit
82     git_test_receive_wrapper: /home/user/source.git/hooks/pre-receive
83     ENV:
84       TMPDIR: /home/user/tmp
85
86 This assumes that your /var/www directory is writable by your user.
87
88 ### Basic HTML rendering
89
90 You should already be able to make a plain HTML rendering of the wiki:
91
92     ikiwiki --setup ikiwiki.setup
93
94 ### Editing your copy through git
95
96 At this point, your wiki should already be visible in `/var/www/mirror.example.com`, the `destdir`. You can edit it and changes should show up automatically in the `destdir`.
97
98 However, you need yet another clone for this, the `srcdir` being used internally by the web interface of Ikiwiki. So clone the `repository` elsewhere:
99
100     git clone ~user/source.git checkout
101     cd checkout
102     edit index.mdwn
103     git commit index.mdwn
104     git push
105
106 This will refresh the main page of the wiki, for example.
107
108 ### Webserver configuration
109
110 You will also need a webserver to serve the content in the `destdir`
111 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.
112
113 Note that this will also configure CGI so that people can edit your copy of the wiki. We'll see how to sync back later.
114
115 #### Apache configuration
116
117     <VirtualHost *:80>
118         ServerName reseaulibre.example.com:80
119         DocumentRoot /var/www/reseaulibre.example.com
120         <Directory /var/www/reseaulibre.example.com>
121             Options Indexes MultiViews ExecCGI
122             AllowOverride None
123             Order allow,deny
124             allow from all
125         </Directory>
126         ScriptAlias /ikiwiki.cgi /var/www/ikiwiki.cgi
127         ErrorDocument 404 "/ikiwiki.cgi"
128     </VirtualHost>
129
130 #### Nginx configuration
131
132     server {
133         root /var/www/reseaulibre.example.com/;
134         index index.html index.htm;
135         server_name reseaulibre.example.com;
136
137         location / {
138             try_files $uri $uri/ /index.html;
139         }
140         location /ikiwiki.cgi {
141             fastcgi_pass  unix:/tmp/fcgi.socket;
142             fastcgi_index ikiwiki.cgi;
143             fastcgi_param SCRIPT_FILENAME   /var/www/ikiwiki.cgi;
144             fastcgi_param  DOCUMENT_ROOT      /var/www/reseaulibre.example.com;
145             include /etc/nginx/fastcgi_params;
146         }
147     }
148
149 Start this process as your own user (or the user that has write access
150 to `srcdir`, `destdir`, etc):
151
152     spawn-fcgi -s /tmp/fcgi.socket -n -- /usr/sbin/fcgiwrap
153
154 Make this writable:
155
156     chmod a+w /tmp/fcgi.socket
157
158 ### Read-only mirror: done!
159
160 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.
161
162 ### Announcing the mirror
163
164 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:
165
166     mirrorlist:
167       example: https://wiki.example.com/
168
169 The [[plugins/mirrorlist]] plugin of course needs to be enabled for this to work.
170
171 ### Pushing changes back to the main site
172
173 The final step is to push edits on the mirror back to the master site. That way the mirror is not only for reading, but can also be edited, even when the master is offline or the network is separated.
174
175 To do this, the mirror needs to push back to the master, again using the gitpush plugin:
176
177     git_push_to:
178     - git://wiki.example.com/
179
180 This will ensure that commits done on the mirror will propagate back to the master.
181
182 ### Other guides
183
184 Another guide is the [[tips/laptop_wiki_with_git]] guide. To get a
185 better understanding of how ikiwiki works, see [[rcs/git]].
186
187 [This](http://piny.be/jrayhawk/notes/ikiwiki_creation/) may also be of
188 use if the above doesn't work.