X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/blobdiff_plain/582e52d3ca79d0d5d0335486718fe2167d6304cd..aa06b950eaa6bbdd20813ac08d4383219a09ab97:/doc/tips/Hosting_Ikiwiki_and_master_git_repository_on_different_machines.mdwn diff --git a/doc/tips/Hosting_Ikiwiki_and_master_git_repository_on_different_machines.mdwn b/doc/tips/Hosting_Ikiwiki_and_master_git_repository_on_different_machines.mdwn index e971a8339..6af4f9619 100644 --- a/doc/tips/Hosting_Ikiwiki_and_master_git_repository_on_different_machines.mdwn +++ b/doc/tips/Hosting_Ikiwiki_and_master_git_repository_on_different_machines.mdwn @@ -1,4 +1,5 @@ [[!meta title="Hosting Ikiwiki with a master git repository on a remote machine"]] +[[!meta date="2013-07-22 16:38:20 -0400"]] This tutorial explains how to set up a wiki such that: @@ -17,6 +18,7 @@ I assume the [[rcs]] used is [[rcs/git]], but it might be done for other rcs. # Similar and related tips and problems +- [[tips/distributed_wikis]] References different way of distributing wikis (including this one). - [[http://www.icanttype.org/blog/ikiwiki_git_remote_repo/]] Similar to what I am describing, excepted that you must be able to connect to the machine hosting Ikiwiki using ssh. @@ -37,6 +39,8 @@ it on a remote machine, and tell Ikiwiki to use it instead of its local one. We will also ensure that the wiki is rendered whenever a commit is done to the git repository. +[[!img separate-web-git-servers.svg size=400x]] + # Conventions - We are building a wiki called *SITE*. @@ -71,7 +75,7 @@ repository. ## Configuring the wiki on the wiki machine so that it uses the repository of the git machine - Configure ssh so that it uses the ssh key `id_SITE` to connect to the git - michine: add the following lines to file `~/.ssh/config` on the ikiwiki + machine: add the following lines to file `~/.ssh/config` on the ikiwiki machine: Host server.name.of.the.git.machine @@ -119,21 +123,36 @@ repository. ## Configure the git repository (on the git machine) to update the wiki after a push -- Add in the `post-receive` hook (file `SITE.git/hooks/post-receive`): +Add in the `post-receive` hook (file `SITE.git/hooks/post-receive`): + + git log -1 --format=format:%ae HEAD | grep -e '@web$' -e 'USER@HOST' || wget "http://WIKI-URL/ikiwiki.cgi?do=ping" -O /dev/stdout - wget "http://WIKI-URL/ikiwiki.cgi?do=ping" -O /dev/stdout +If your wiki is password protected, use: - If your wiki is password protected, use: + 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 - wget "http://LOGIN:PASSWORD@WIKI-URL/ikiwiki.cgi?do=ping" -O /dev/stdout +The bit before `wget` is here to prevent updating the wiki while it is +updating, which can lead to a deadlock. Indeed, when the wiki is edited via +web, or a tag page is automatically added, IkiWiki pushes the changes to the +Git machine. Then, the hook on this latter machine tries to pull changes from +the IkiWiki machine, and here is the deadlock. Explanations of the command: +* `git log -1 --format=format:%ae HEAD`: Looks for the user name of the + latest commit. +* `grep -e '@web$' -e 'USER@HOST': Check whether this last commit was pushed + from the IkiWiki machine (change `USER@HOST` to the appropriate string). +* `wget ...`: If the last commit does not come from the IkiWiki machine + (which means it comes from another machine), update the wiki. ## Going further - *Web server on a third machine* It should be possible to use a third machine - to host the web server. A hook might be used to export the rendered wiki on - this server, or use a nfs repository as the destination repository of - ikiwiki. However, allowing web modifications (using CGI) might be tricky… + to host the web server, using [[this documentation|tips/Git_repository_and_web_server_on_different_hosts/]]. - *Using [[gitolite|https://github.com/sitaramc/gitolite]] to manage repositories on the git machine* Simply replace the manipulations of git on the git machine by the corresponding manipulations using gitolite. + * With gitolite, you can use this line in a `post-update` hook: + + `[ x"$GL_USER" = x"`*`gitolite-user`*`" ] || wget ...` where *gitolite-user* is the name of the public key registered through gitolite. + + 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).