[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: Updating a live website with a post-commit hook script

From: I. E. Smith-Heisters <public_at_0x09.com>
Date: 2006-06-29 15:50:12 CEST

You can also get a bit more fancy about it. If you run "svn up" on the
root of your working directory, it has to churn through the whole
directory, which can take quite some time depending on the size of
your codebase. Instead, you can use post-commit's arguments to
specifically update files, which, IME, cuts the update time to about
1/10th of the time. Here's an example in Perl:

#!/usr/bin/perl

use warnings;
use strict;

my ($REPOS, $REV) = @ARGV;
my $working_dir = '/var/www';
open (P, "/usr/bin/svnlook changed $REPOS|");

while (<P>) {
        $_ =~ /^.\s+(.*$)/;
        my $file = $1;

        $file =~ s/website\/trunk//;
        system("/usr/bin/svn up $working_dir/Website/$file");
}

So, that would take a repo path of /website/trunk/file and update the
filesystem file /var/www/Website/file. I actually haven't tested the
code above, it's part of a larger script, but something like that
should work.

-Ian

On 6/29/06, Bob Proulx <bob@proulx.com> wrote:
> Graham Anderson wrote:
> > 1) Is there an example script and tutorial on how to update a live
> > web site with a post-commit hook script ?
>
> I don't know if official examples exist but the implementation is
> really only a few lines.
>
> > 2) Does this comply with a 'best practices' use for subversion ? At
> > this point, I am a bit too green to evaluate if this is ok.
>
> Yes. This is a best practice. It is recommended in the FAQ as you
> noted in your message.
>
> http://subversion.tigris.org/faq.html#website-auto-update
>
> Let's assume a subversion repository at /srv/svn/www and a web
> document root at /srv/www. You could have a post-commit hook at
> /srv/svn/www/hooks/post-commit with this content:
>
> #!/bin/sh
> cd /srv/www || exit 1
> svn update --quiet
> exit 0
>
> A very simple process. Change directory to the live web working copy
> and update it.
>
> This process will run as the web process uid. On my machine that
> means the www-data user. On other machines it will be different. The
> live working copy needs to be owned by the www-data user or at least
> be writable by it so that the web server uid can update it.
>
> Of course you don't need to use the https:// protocol to update. You
> could use the svn+ssh:// protocol. But if you are updating a web page
> then we can assume that you have a web server and so have https://
> available. This avoids a permission problem.
>
> If you use svn+ssh:// then the post-commit is run as the committing
> uid which will be different for everyone. For a web server document
> root keeping it writable by everyone is probably not what you want to
> do. This is where the little C program wrapper described in the FAQ
> becomes useful. Set up a set-uid program to switch to a pseudo user
> to update the web document root. Make it writable only by that pseudo
> user.
>
> Hope that helps!
> Bob
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
> For additional commands, e-mail: users-help@subversion.tigris.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org
Received on Thu Jun 29 15:52:15 2006

This is an archived mail posted to the Subversion Users mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.