0

So I have SVN installed on our web server. The idea is that the working copies are loaded on developer machines and when they commit (conflicts asside) the server executes a post-commit bash.

Repositories are per project based, the idea is that upon post-commit, the bash file needs to force delete the entire project folder and files, and export the updated repo back into the project folder, to keep the website updated via SVN... I know there's bound to be some disagreements with this method but it works for us... except for ONE thing...

While the server is re-exporting the project, any requests being made to the website raise errors since there's chunks of files missing... Is there any way to "queue" apache/php while SVN exports, and then "resume" the requests?

The server exports the files pretty quickly but it's those few millisecs that someone catches the server and raises PHP errors...

Please let me know if there's a typical method to sort this out...

Thanks

Prof
  • 2,898
  • 1
  • 21
  • 38

4 Answers4

2

You could minimize the interruption by building the content in a new directory tree and then renamings things. That is, assuming that you content is available under /var/www/myproject, your post-update script would:

  • Populate /var/www/myproject.new
  • Rename /var/www/myproject to /var/www/myproject.old
  • Rename /var/www/myproject.new to /var/www/myproject
  • Delete /var/www/myproject.old

While not quite an atomic update, the time required to perform the two renames will be minimal and should greatly improve the situation.

Prof
  • 2,898
  • 1
  • 21
  • 38
larsks
  • 277,717
  • 41
  • 399
  • 399
1
  1. You can export not the whole tree, but only files, affected in this revision and replace files without deleting site
  2. You still can perform full export and full replace, but not delete site in hook, only overwrite on top of old files (deleted in revision files, which you leave intact on site, doesn't broke it because they are unrelated) and perform full sync (daily or weekly) in night cron-job
Lazy Badger
  • 94,711
  • 9
  • 78
  • 110
0

I don't know if is the following is useful in your case but you could make a two step code upgrading script:

  1. SVN checkout in tempdir
  2. Replace all the code in your production directory with data contained in tempdir
  3. Delete tempdir

You will never go through conflicts.

BTW I don't think this is a best practice. You should resolve conflicts on clients developers machines.

  • "Conflicts asside" This isn't about resolving conflicts, SVN helps with that before you commit... But thanks anyway, @larsks makes good sense – Prof Dec 01 '12 at 18:40
0

I really feel that @Larsks' answer was practical enough to provide an almost atomic and needed solution at the time, so I am keeping his answer as "correct" but thought i'd contribute taking This Post into consideration as well:

Assuming that mv is fully atomic, the post-commit hook bash could look like this:

svn export file:///svn/repo /var/www/projectdir_NEW --force
mv /var/www/projectdir /var/www/projectdir_OLD
mv /var/www/projectdir_NEW /var/www/projectdir
rm -rf mv /var/www/projectdir_OLD

The only thing is the few split seconds between the 2 mv commands, and this is the closest to atomic and cleanest way to do this... BUT, for a fully atomic affect, let's say I don't mind using a little PHP and since my project has a global init.php, post-commit could do this:

date > /var/www/projectdir.updating
svn export file:///svn/repo /var/www/projectdir_NEW --force
mv /var/www/projectdir /var/www/projectdir_OLD
mv /var/www/projectdir_NEW /var/www/projectdir
rm -rf mv /var/www/projectdir_OLD
rm /var/www/projectdir.updating

Creates a temporary file called "projectdir.updating" with the date in it, executes the update, then deletes the temp file, I can now use my init.php to "throttle" any requests:

while (file_exists("/var/www/projectdir.updating")) usleep(200);

Furthermore I could check the date detail saved in the temp file for an exit with an error... (if the export failes to remove the .updating file)

Community
  • 1
  • 1
Prof
  • 2,898
  • 1
  • 21
  • 38