1 [[!meta title="Hosting Ikiwiki with a master git repository on a remote machine"]]
3 This tutorial explains how to set up a wiki such that:
5 - the machine running Ikiwiki is not the same as the one hosting the git repository;
6 - changes can be done using CGI;
7 - changes can be done using git (using ssh protocol).
9 This configuration may be useful when:
11 - you do not want (or cannot) connect to the machine hosting your wiki using
13 - you do not want (or cannot) publish web content on the machine hosting you
14 remotely accessible git repository.
16 I assume the [[rcs]] used is [[rcs/git]], but it might be done for other rcs.
18 # Similar and related tips and problems
20 - [[tips/distributed_wikis]] References different way of distributing wikis (including this one).
21 - [[http://www.icanttype.org/blog/ikiwiki_git_remote_repo/]] Similar to what I
22 am describing, excepted that you must be able to connect to the machine
23 hosting Ikiwiki using ssh.
24 - [[forum/How_to_specify_repository_is_on_a_remote_host__63__]] My solution
25 solves the problem described here, excepted that svn is used there, and in
26 the comments, Joey advice not to do this with svn.
27 - [[forum/how_to_setup_ikiwiki_on_a_remote_host]] My solution might answer this
32 By default, when creating a wiki, Ikiwiki creates and uses two repositories: a
33 bare repository, and a « slave » repository, used as the source to render the
34 wiki. All of these are on the same machine.
36 Instead of having the bare repository hosted on the same machine, we will host
37 it on a remote machine, and tell Ikiwiki to use it instead of its local one. We
38 will also ensure that the wiki is rendered whenever a commit is done to the git
43 - We are building a wiki called *SITE*.
44 - The machine running Ikiwiki and a web server is called the *Ikiwiki machine*.
45 - The machine hosting the git repository is called the *git machine*. Users can
46 make git pull and push to this machine.
50 ## Creating ssh keys on the Ikiwiki machine
52 - Create a pair of ssh keys, not password-protected (as they will be used by
53 script). Let's call them `id_SITE` and `id_SITE.pub`. These keys will be used
54 by the ikiwiki machine to connect to the git machine.
56 ## Creating and setting up a repository on the git machine
58 - Create a repository `SITE.git` on the git machine (using `git init --bare`),
59 and ensure that public key `id_SITE.pub` can pull from and push to this
60 repository (using `~/.ssh/config` or by setting the right permissions on
63 ## Creating the wiki on the ikiwiki machine
65 - Create the wiki following [[the regular procedure|setup]]. You should have,
66 among others, a directory `SITE.git`, being the master git repository, and a
67 directory `SITE`, clone of `SITE.git`, used as source directory to render the
69 - Ensure that your web server can serve the rendered wiki, and that changes can
72 ## Configuring the wiki on the wiki machine so that it uses the repository of the git machine
74 - Configure ssh so that it uses the ssh key `id_SITE` to connect to the git
75 michine: add the following lines to file `~/.ssh/config` on the ikiwiki
78 Host server.name.of.the.git.machine
80 IdentityFile ~/.ssh/id_SITE
82 - Configure the local copy `SITE` of the wiki (on the ikiwiki machine) to use
83 the remote git repository instead of the local `SITE.git`. To do so, in the
84 file `SITE/.git/config`, replace the lines:
87 url = /path/to/SITE.git
88 fetch = +refs/heads/*:refs/remotes/origin/*
93 url = git-machine-user@server.name.of.the.git.machine:SITE.git
94 fetch = +refs/heads/*:refs/remotes/origin/*
96 - In this repository (`SITE`), run `git pull` and `git push` to ensure that
97 everything works fine. It *works fine* when you will be able to run `git
98 pull` and `git push` without user interaction.
100 - Disable the `post-update` hook in ikiwiki: it is used if the git commits are
101 done on this machine, which is no longer the case. To do so, in file
102 `SITE.setup`, comment the line:
104 git_wrapper => '/path/to/SITE.git/hooks/post-update',
106 - Tell Ikiwiki to push to the ikiwiki machine when a commit is done by the web
107 (CGI). To do so, in file `SITE.setup`, add the line:
109 git_wrapper_background_command => 'git push',
111 - Enable plugin [[pingee|http://ikiwiki.info/plugins/pingee/]]. It allows git
112 (on the git machine) to tell ikiwiki to update and rebuild the wiki when
113 commits are done on the git repository, using only an http connection. To do
114 so, add `pingee` to the list of enabled plugins (variable `add_plugins` in
117 - Rebuild the wiki (since you chaned the setup file `SITE.setup`).
119 ikiwiki --setup SITE.setup --rebuild --verbose
121 ## Configure the git repository (on the git machine) to update the wiki after a push
123 Add in the `post-receive` hook (file `SITE.git/hooks/post-receive`):
125 git log -1 --format=format:%ae HEAD | grep -e '@web$' -e 'USER@HOST' || wget "http://WIKI-URL/ikiwiki.cgi?do=ping" -O /dev/stdout
127 If your wiki is password protected, use:
129 git log -1 --format=format:%ae HEAD | grep -e '@web$' -e 'USER@HOST' || wget "http://LOGIN:PASSWORD@WIKI-URL/ikiwiki.cgi?do=ping" -O /dev/stdout
131 The bit before `wget` is here to prevent updating the wiki while it is
132 updating, which can lead to a deadlock. Indeed, when the wiki is edited via
133 web, or a tag page is automatically added, IkiWiki pushes the changes to the
134 Git machine. Then, the hook on this latter machine tries to pull changes from
135 the IkiWiki machine, and here is the deadlock. Explanations of the command:
137 * `git log -1 --format=format:%ae HEAD`: Looks for the user name of the
139 * `grep -e '@web$' -e 'USER@HOST': Check whether this last commit was pushed
140 from the IkiWiki machine (change `USER@HOST` to the appropriate string).
141 * `wget ...`: If the last commit does not come from the IkiWiki machine
142 (which means it comes from another machine), update the wiki.
146 - *Web server on a third machine* It should be possible to use a third machine
147 to host the web server, using [[this documentation|tips/Git_repository_and_web_server_on_different_hosts/]].
148 - *Using [[gitolite|https://github.com/sitaramc/gitolite]] to manage
149 repositories on the git machine* Simply replace the manipulations of git on
150 the git machine by the corresponding manipulations using gitolite.
151 * With gitolite, you can use this line in a `post-update` hook:
153 `[ x"$GL_USER" = x"`*`gitolite-user`*`" ] || wget ...`
155 thus, you filter out precisely the events that originate from the server-to-be-pinged, no matter what the commit id says. (For example, if you push commits you created on a local CGI ikiwiki, they'd be called '@web' as well).