install subversion server on Ubuntu

This is a guide for installing subversion on a Ubuntu server, using svnserve (easiest installation, I personally always handle security by only allowing remote (off-site) access using a ssh tunnel), and with e-mail notification on commits.

For starters, you need to install subversion.

apt-get install subversion libsvn-notify-perl

As root, create a file “/etc/init.d/svn” with the following content

#! /bin/sh

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/bin/svnserve
NAME=svn
DESC="Subversion Server"

SVNOPTS="--listen-port 3692 -r /data/svn -d"
USER="svn"

test -x $DAEMON || exit 0

set -e

case "$1" in
  start)
        echo -n "Starting $DESC: "
        start-stop-daemon -u $USER --start --quiet --exec $DAEMON -- $SVNOPTS
        echo "$NAME."
        ;;
  stop)
        echo -n "Stopping $DESC: "
        start-stop-daemon -u $USER --stop --oknodo --quiet --exec $DAEMON
        echo "$NAME."
        ;;
  restart|force-reload)
        echo -n "Restarting $DESC: "
        start-stop-daemon -u $USER --stop --oknodo --quiet --exec $DAEMON
        sleep 1
        start-stop-daemon -u $USER --start --quiet --exec $DAEMON -- $SVNOPTS
        echo "$NAME."
        ;;
  *)
        N=/etc/init.d/$NAME
        echo "Usage: $N {start|stop|restart|force-reload}" >&2
        exit 1
        ;;
esac

exit 0

You should modify the part and base directory where the repositories are stored in the SVNOPTS line. I changed the default port (normally 3690) as this makes it easier for me to access the repository from either the local network or remotely when tunnelled through ssh as the port can be the same in both cases (and not clash with a local svn installation).
Make sure this is executable, link as startup file, create svn user and start.
chmod a+x /etc/init.d/svn
ln -s /etc/init.d/svn /etc/rc2.d/S99svn
adduser --system svn
/etc/init.d/svn start

You can now create your first repository.
svnadmin create /data/svn/test

To assure password login, edit “/data/svn/test/conf/svnserve.conf” and uncomment the line “password-db=passwd”. Then edit the /data/svn/test/conf/passwd file to set login and password for each of the users.

If you want post-commit e-mail messages, then enable the post-commit hook script.

mv /data/svn/test/hooks/post-commit.tmpl /data/svn/test/hooks/post-commit

Now edit this script to assure the e-mail address is correct (should be a mailing list address).
The script send the messages by the local smtp server, so make sure this is installed (possibly to forward the mail to a suitable mail server).

4 Comments

  1. Dirk Wetter says:

    Thanks for that. Don’t know why Ubuntu doens’t seem to come with an init script for it.

    One thing: If would omit /usr/local. It doensn’t make
    any sense here and under certain cicrumstances
    you run into security oder stanbilty problems.
    Imagine you share /usr/local via NFS. Details see
    http://drwetter.org/suse10.1/report.suse-10.1.html#usr-local

    Cheers, Dirk

  2. Dennis Matutina says:

    Hi,

    Just wondering whether you have made post-commit email work with Tortoise SVN?

  3. joachim says:

    What do you mean by “with Tortoise svn”? If the commit hook works for one client, it should work for all…

  4. […] lovers). But the best solution for server installation as for me is stated by Joachim in his blog. Works great! LD_AddCustomAttr("AdOpt", "1"); LD_AddCustomAttr("Origin", "other"); […]

Leave a Reply

Your email address will not be published. Required fields are marked *

question razz sad evil exclaim smile redface biggrin surprised eek confused cool lol mad twisted rolleyes wink idea arrow neutral cry mrgreen

*