Install Subversion Trac Nginx on Ubuntu Hardy

The following are my notes for setting up is Subversion & Trac behind Nginx. I’m sure there are other ways to do this, but this is what I did, and it worked for me.

Install Python Setup Tools, Subversion, and TRAC:

aptitude install python-setuptools subversion python-subversion
easy_install trac

Create a subversion repository:

mkdir /var/lib/svn
mkdir /var/lib/svn/repositories
svnadmin create /var/lib/svn/repositories/ProjectName
chown -R www-data /var/lib/svn

Edit /var/lib/svn/repositories/ProjectName/conf/svnserve.conf and change to the following:

anon-access = none
auth-access = write
password-db = /var/lib/svn/repositories/ProjectName/conf/passwd
realm = ProjectName

Edit /var/lib/svn/ProjectName/passwd:

[users]
yourusername = yourpassword

Create init.d script to startup svnserve on boot, /etc/init.d/svnserve :

#!/bin/sh
#
# This starts and stops svnserv. Put this in /etc/init.d/svnserve.
# This works on both Ubuntu and RedHat systems.
# On Ubuntu, run "update-rc.d svnserve defaults" to install this on startup.
# On RedHat, run "chkconfig --add svnserve" to install this on startup.
#
# $Id: svnserve 98 2007-10-30 22:01:36Z noah $
#
# chkconfig: 2345 90 10
# description: svnserve daemon start script
 
# Use the following variables to customize user, group, and paths.
SVNSERVE=`which svnserve`
SVN_USER=svn
SVN_GROUP=svn
SVN_ROOT_PATH=/var/lib/svn/repositories/
 
if [ -f /etc/rc.d/init.d/functions ]; then
    # RedHat style
    . /etc/rc.d/init.d/functions
    START="daemon $SVNSERVE -d --root $SVN_ROOT_PATH"
    STOP="killproc $SVNSERVE"
else
    # Ubuntu LSB style
    . /lib/lsb/init-functions
    START="start-stop-daemon --start --exec $SVNSERVE -- -d --root $SVN_ROOT_PATH"
    STOP="start-stop-daemon --stop --exec $SVNSERVE"
fi
 
if [ ! -x $SVNSERVE ]; then
    echo "Could not find ${SVNSERVE}. PATH is ${PATH}"
    exit 0
fi
 
case "$1" in
    start)
        echo "Starting svnserve..."
        umask 002
        $START
        if [ $? ]; then
            echo "Started svnserve"
            exit 0
        else
            exit $?
        fi
    ;;
 
    stop)
        echo "Stopping svnserve..."
        $STOP
        exit $?
    ;;
 
    restart|force-reload)
        "$0" stop && "$0" start
    ;;
 
    *)
    echo "Usage: /etc/init.d/svnserve {start|stop|restart|force-reload}"
        exit 1
    ;;
esac
 
echo "Unhandled case while trying to start svnserve."
echo "see $0"
exit 3

Make it startup on boot:

cd /etc/init.d
update-rc.d svnserve defaults

Ok, subversion is done, now lets create a trac environment.

Create a place for our trac environments to live:

mkdir /var/lib/trac

Create Trac environment:

mkdir /var/lib/trac
trac-admin /var/lib/trac/ProjectName initenv
chown -R www-data /var/lib/trac

The “trac-admin” command shown above prompted me to enter:

  • the project name (ProjectName)
  • the path to svn repository (/var/lib/svn/ProjectName)

Add a user with the Apache htpasswd tool:

htpasswd -c /var/lib/trac/test/.htpasswd youruser

Startup the trac standalone server tracd:

tracd -d -p 3050 --basic-auth=test,/var/lib/trac/ProjectName/.htpasswd,/var/lib/trac/ProjectName /var/lib/trac/ProjectName --pidfile=/var/lib/trac/tracd.3050

Create admin account and revoke almost all anonymous permissions from trac:

trac-admin /var/lib/trac/<environment name> permission add youruser TRAC_ADMIN
trac-admin /var/lib/trac/<environment name> permission remove anonymous BROWSER_VIEW CHANGESET_VIEW FILE_VIEW LOG_VIEW MILESTONE_VIEW REPORT_SQL_VIEW REPORT_VIEW ROADMAP_VIEW SEARCH_VIEW TICKET_CREATE TICKET_MODIFY TICKET_VIEW TIMELINE_VIEW WIKI_CREATE WIKI_MODIFY

If you have an iptables setup or other firewall, don’t forget to allow connections to port 3690. Assuming your using slicehost like me, you can do the following:

Edit /etc/iptables.test.rules and add the following before any final LOG & REJECT rules:

# Allows svnserve connections from anywhere
-A INPUT -p tcp --dport 3690 -j ACCEPT

Activate the changes:

iptables-restore < /etc/iptables.test.rules

Save the changes:

iptables-save > /etc/iptables.up.rules

Startup SVNserve:

svnserve -d -r /var/lib/svn/ProjectName

Make SVNserve startup on reboot add the following to your crontab:

crontab -e
@reboot svnserve -d -r /var/lib/svn/ProjectName

You should now be able to checkin/checkout from your repository & visit http://trac.example.com to see your trac environment.

0 comments ↓

There are no comments yet...Kick things off by filling out the form below.

Leave a Comment