]> sipb.mit.edu Git - ikiwiki.git/blob - doc/tips/Hosting_Ikiwiki_and_master_git_repository_on_different_machines.mdwn
Change Projects link to point to projects DB
[ikiwiki.git] / doc / tips / Hosting_Ikiwiki_and_master_git_repository_on_different_machines.mdwn
1 [[!meta title="Hosting Ikiwiki with a master git repository on a remote machine"]]
2
3 This tutorial explains how to set up a wiki such that:
4
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).
8
9 This configuration may be useful when:
10
11 - you do not want (or cannot) connect to the machine hosting your wiki using
12   `git` or `ssh`;
13 - you do not want (or cannot) publish web content on the machine hosting you
14   remotely accessible git repository.
15
16 I assume the [[rcs]] used is [[rcs/git]], but it might be done for other rcs.
17
18 # Similar and related tips and problems
19
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
28   problem.
29
30 # Overview
31
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.
35
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
39 repository.
40
41 [[!img separate-web-git-servers.svg size=400x]]
42
43 # Conventions
44
45 - We are building a wiki called *SITE*.
46 - The machine running Ikiwiki and a web server is called the *Ikiwiki machine*.
47 - The machine hosting the git repository is called the *git machine*. Users can
48   make git pull and push to this machine.
49
50 # Let's go!
51
52 ## Creating ssh keys on the Ikiwiki machine
53
54 - Create a pair of ssh keys, not password-protected (as they will be used by
55   script). Let's call them `id_SITE` and `id_SITE.pub`. These keys will be used
56   by the ikiwiki machine to connect to the git machine.
57
58 ## Creating and setting up a repository on the git machine
59
60 - Create a repository `SITE.git` on the git machine (using `git init --bare`),
61   and ensure that public key `id_SITE.pub` can pull from and push to this
62   repository (using `~/.ssh/config` or by setting the right permissions on
63   gitolite or gitosis).
64
65 ## Creating the wiki on the ikiwiki machine
66
67 - Create the wiki following [[the regular procedure|setup]]. You should have,
68   among others, a directory `SITE.git`, being the master git repository, and a
69   directory `SITE`, clone of `SITE.git`, used as source directory to render the
70   wiki.
71 - Ensure that your web server can serve the rendered wiki, and that changes can
72   be done with CGI.
73
74 ## Configuring the wiki on the wiki machine so that it uses the repository of the git machine
75
76 - Configure ssh so that it uses the ssh key `id_SITE` to connect to the git
77   michine: add the following lines to file `~/.ssh/config` on the ikiwiki
78   machine:
79
80         Host server.name.of.the.git.machine
81             User git-machine-user
82             IdentityFile ~/.ssh/id_SITE
83
84 - Configure the local copy `SITE` of the wiki (on the ikiwiki machine) to use
85   the remote git repository instead of the local `SITE.git`. To do so, in the
86   file `SITE/.git/config`, replace the lines:
87
88         [remote "origin"]
89                url = /path/to/SITE.git
90                fetch = +refs/heads/*:refs/remotes/origin/*
91
92   by the lines:
93
94         [remote "origin"]
95                 url = git-machine-user@server.name.of.the.git.machine:SITE.git
96                 fetch = +refs/heads/*:refs/remotes/origin/*
97
98 - In this repository (`SITE`), run `git pull` and `git push` to ensure that
99   everything works fine. It *works fine* when you will be able to run `git
100   pull` and `git push` without user interaction.
101
102 - Disable the `post-update` hook in ikiwiki: it is used if the git commits are
103   done on this machine, which is no longer the case. To do so, in file
104   `SITE.setup`, comment the line:
105
106         git_wrapper => '/path/to/SITE.git/hooks/post-update',
107
108 - Tell Ikiwiki to push to the ikiwiki machine when a commit is done by the web
109   (CGI). To do so, in file `SITE.setup`, add the line:
110
111         git_wrapper_background_command => 'git push',
112
113 - Enable plugin [[pingee|http://ikiwiki.info/plugins/pingee/]]. It allows git
114   (on the git machine) to tell ikiwiki to update and rebuild the wiki when
115   commits are done on the git repository, using only an http connection. To do
116   so, add `pingee` to the list of enabled plugins (variable `add_plugins` in
117   file `SITE.setup`).
118
119 - Rebuild the wiki (since you chaned the setup file `SITE.setup`).
120
121         ikiwiki --setup SITE.setup --rebuild --verbose
122
123 ## Configure the git repository (on the git machine) to update the wiki after a push
124
125 Add in the `post-receive` hook (file `SITE.git/hooks/post-receive`):
126
127       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
129 If your wiki is password protected, use:
130
131       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
133 The bit before `wget` is here to prevent updating the wiki while it is
134 updating, which can lead to a deadlock. Indeed, when the wiki is edited via
135 web, or a tag page is automatically added, IkiWiki pushes the changes to the
136 Git machine. Then, the hook on this latter machine tries to pull changes from
137 the IkiWiki machine, and here is the deadlock. Explanations of the command:
138
139 * `git log -1 --format=format:%ae HEAD`: Looks for the user name of the
140   latest commit.
141 * `grep -e '@web$' -e 'USER@HOST': Check whether this last commit was pushed
142   from the IkiWiki machine (change `USER@HOST` to the appropriate string).
143 * `wget ...`: If the last commit does not come from the IkiWiki machine
144   (which means it comes from another machine), update the wiki.
145
146 ## Going further
147
148 - *Web server on a third machine* It should be possible to use a third machine
149   to host the web server, using [[this documentation|tips/Git_repository_and_web_server_on_different_hosts/]].
150 - *Using [[gitolite|https://github.com/sitaramc/gitolite]] to manage
151   repositories on the git machine* Simply replace the manipulations of git on
152   the git machine by the corresponding manipulations using gitolite.
153     * With gitolite, you can use this line in a `post-update` hook:
154
155         `[ x"$GL_USER" = x"`*`gitolite-user`*`" ] || wget ...` where *gitolite-user* is the name of the public key registered through gitolite.
156
157         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).