kelan.io

Trac svn post-commit hook on Dreamhost

This is just a quick post to let google and friends know how I solved a problem setting up the svn post-commit hook for Trac on Dreamhost. (As a side note, I noticed they just introduced a 1-click install for Trac, and I’m not sure if it includes the post-commit hook or not. I installed the old-fashioned way.)

The problem was that svn is run as a different user, and since I want to keep my Trac SQLite database file locked down (so only my user can read/write it), the post-commit hook script did not have permissions to do what it needed to do. The solution was to make the post-commit hook script just write the repo and rev number to an intermediate file, and then have cron run a script (as my user) that actually runs the Trac script every so often, using the args from that intermediate file.

I put this as the actual svn post-commit script (in the file ~/myUser/svn/myRepo/hooks/post-commit):

#!/bin/sh

REPOS="$1"
REV="$2"

# Just append this info to the log file
echo "$REPOS:$REV" >> /home/myUser/trac_projects/myProject/queued_post_commits.txt

It simply writes the repo and rev to the intermediate file. This log file has to be writable by the svn user, but it’s the only file that has to have relaxed permissions, and should be pretty safe to do so. Better than opening up your whole Trac project, at least.

Then, I added this to my crontab:

0,5,10,15,20,25,30,35,40,45,50,55 * * * * ~/trac_projects/myProject/run-queued-trac-post-commits.rb

Which simply runs this script every 5 minutes, which does the actual processing of the queued commits. It lives at ~/trac_projects/myProject/run-queued-trac-post-commits.rb.

As a warning, I went a little overboard with logging of successes and errors, but didn’t get crazy enough to actually clean out those log files (especially queued_post_commits_done.txt). So, if you have a high volume of commits, you might want to improve that situation a bit. But it shouldn’t be an issue if you have relatively few commits, like I do.

Thats it. I hope this helps somebody out there!