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 - [[http://www.icanttype.org/blog/ikiwiki_git_remote_repo/]] Similar to what I
21 am describing, excepted that you must be able to connect to the machine
22 hosting Ikiwiki using ssh.
23 - [[forum/How_to_specify_repository_is_on_a_remote_host__63__]] My solution
24 solves the problem described here, excepted that svn is used there, and in
25 the comments, Joey advice not to do this with svn.
26 - [[forum/how_to_setup_ikiwiki_on_a_remote_host]] My solution might answer this
31 By default, when creating a wiki, Ikiwiki creates and uses two repositories: a
32 bare repository, and a « slave » repository, used as the source to render the
33 wiki. All of these are on the same machine.
35 Instead of having the bare repository hosted on the same machine, we will host
36 it on a remote machine, and tell Ikiwiki to use it instead of its local one. We
37 will also ensure that the wiki is rendered whenever a commit is done to the git
40 [[!img separate-web-git-servers.svg size=400x]]
44 - We are building a wiki called *SITE*.
45 - The machine running Ikiwiki and a web server is called the *Ikiwiki machine*.
46 - The machine hosting the git repository is called the *git machine*. Users can
47 make git pull and push to this machine.
51 ## Creating ssh keys on the Ikiwiki machine
53 - Create a pair of ssh keys, not password-protected (as they will be used by
54 script). Let's call them `id_SITE` and `id_SITE.pub`. These keys will be used
55 by the ikiwiki machine to connect to the git machine.
57 ## Creating and setting up a repository on the git machine
59 - Create a repository `SITE.git` on the git machine (using `git init --bare`),
60 and ensure that public key `id_SITE.pub` can pull from and push to this
61 repository (using `~/.ssh/config` or by setting the right permissions on
64 ## Creating the wiki on the ikiwiki machine
66 - Create the wiki following [[the regular procedure|setup]]. You should have,
67 among others, a directory `SITE.git`, being the master git repository, and a
68 directory `SITE`, clone of `SITE.git`, used as source directory to render the
70 - Ensure that your web server can serve the rendered wiki, and that changes can
73 ## Configuring the wiki on the wiki machine so that it uses the repository of the git machine
75 - Configure ssh so that it uses the ssh key `id_SITE` to connect to the git
76 michine: add the following lines to file `~/.ssh/config` on the ikiwiki
79 Host server.name.of.the.git.machine
81 IdentityFile ~/.ssh/id_SITE
83 - Configure the local copy `SITE` of the wiki (on the ikiwiki machine) to use
84 the remote git repository instead of the local `SITE.git`. To do so, in the
85 file `SITE/.git/config`, replace the lines:
88 url = /path/to/SITE.git
89 fetch = +refs/heads/*:refs/remotes/origin/*
94 url = git-machine-user@server.name.of.the.git.machine:SITE.git
95 fetch = +refs/heads/*:refs/remotes/origin/*
97 - In this repository (`SITE`), run `git pull` and `git push` to ensure that
98 everything works fine. It *works fine* when you will be able to run `git
99 pull` and `git push` without user interaction.
101 - Disable the `post-update` hook in ikiwiki: it is used if the git commits are
102 done on this machine, which is no longer the case. To do so, in file
103 `SITE.setup`, comment the line:
105 git_wrapper => '/path/to/SITE.git/hooks/post-update',
107 - Tell Ikiwiki to push to the ikiwiki machine when a commit is done by the web
108 (CGI). To do so, in file `SITE.setup`, add the line:
110 git_wrapper_background_command => 'git push',
112 - Enable plugin [[pingee|http://ikiwiki.info/plugins/pingee/]]. It allows git
113 (on the git machine) to tell ikiwiki to update and rebuild the wiki when
114 commits are done on the git repository, using only an http connection. To do
115 so, add `pingee` to the list of enabled plugins (variable `add_plugins` in
118 - Rebuild the wiki (since you chaned the setup file `SITE.setup`).
120 ikiwiki --setup SITE.setup --rebuild --verbose
122 ## Configure the git repository (on the git machine) to update the wiki after a push
124 Add in the `post-receive` hook (file `SITE.git/hooks/post-receive`):
126 git log -1 --format=format:%ae HEAD | grep -e '@web$' -e 'USER@HOST' || wget "http://WIKI-URL/ikiwiki.cgi?do=ping" -O /dev/stdout
128 If your wiki is password protected, use:
130 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
132 The bit before `wget` is here to prevent updating the wiki while it is
133 updating, which can lead to a deadlock. Indeed, when the wiki is edited via
134 web, or a tag page is automatically added, IkiWiki pushes the changes to the
135 Git machine. Then, the hook on this latter machine tries to pull changes from
136 the IkiWiki machine, and here is the deadlock. Explanations of the command:
138 * `git log -1 --format=format:%ae HEAD`: Looks for the user name of the
140 * `grep -e '@web$' -e 'USER@HOST': Check whether this last commit was pushed
141 from the IkiWiki machine (change `USER@HOST` to the appropriate string).
142 * `wget ...`: If the last commit does not come from the IkiWiki machine
143 (which means it comes from another machine), update the wiki.
147 - *Web server on a third machine* It should be possible to use a third machine
148 to host the web server. A hook might be used to export the rendered wiki on
149 this server, or use a nfs repository as the destination repository of
150 ikiwiki. However, allowing web modifications (using CGI) might be tricky…
151 - *Using [[gitolite|https://github.com/sitaramc/gitolite]] to manage
152 repositories on the git machine* Simply replace the manipulations of git on
153 the git machine by the corresponding manipulations using gitolite.
154 * With gitolite, you can use this line in a `post-update` hook:
156 `[ x"$GL_USER" = x"`*`gitolite-user`*`" ] || wget ...`
158 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).