Sergei Chumakov
Library | CTR | Campus | Stanford | Google | Wiki

os x howto

hosting SVN server on your Mac (under OS X Leopard)


I do not assume any responsibility for any damage resulting from you following these instructions. The sequence of steps described below worked fine for me. As always, YMMV. Use at your own risk.

Credit for the plist file goes to James Huddleston.

This tutorial describes the basic setup when your SVN repository:

  • is open to anyone (to set up passwords and users, follow up with this section of the SVN online manual)
  • does not use any authentication except the one that is built into SVN by default CRAM-MD5 authentication challenge. At no time the password is traveling over the internet. If you want more security, check out this chapter of the SVN online manual.

why would you want to host a SVN server?

Recently I realized that I've acquired many projects that needed some structuring. It seems logical to introduce some sort of a version control, and keep my projects in one place (my workstation) which would be backed up on a regular basis. I decided to backup my files with Leopard's build-in feature called Time Machine, and use the Subversion (SVN) to track the changes in my codes and webpages. SVN server has many advantages &mdash you can access your code from anywhere, you can share your code in a controlled manner, and (probably the most important aspect) if you introduce a bug in your code at some point, you can revert to earlier version.

launch the SVN daemon

First, enable SVN server on your computer. Leopard comes with a user _svn and group _svn installed, so you might as well use it to host your repositories. So first thing we want to do is use launchd utility to launch the SVN daemon svnserve.

To do this, type
sudo vi /Library/LaunchDaemons/org.tigris.subversion.svnserve.plist

Then copy the following into the window:

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" ""> <plist version="1.0"> <dict> <key>Disabled</key> <false/> <key>Label</key> <string>org.tigris.subversion.svnserve</string> <key>UserName</key> <string>_svn</string> <key>GroupName</key> <string>_svn</string> <key>Umask</key> <string>002</string> <key>ProgramArguments</key> <array> <string>/usr/bin/svnserve</string> <string>--inetd</string> <string>--root=/Users/Shared/svn</string> </array> <key>ServiceDescription</key> <string>Subversion Standalone Server</string> <key>Sockets</key> <dict> <key>Listeners</key> <array> <dict> <key>SockFamily</key> <string>IPv4</string> <key>SockServiceName</key> <string>svn</string> <key>SockType</key> <string>stream</string> </dict> <dict> <key>SockFamily</key> <string>IPv6</string> <key>SockServiceName</key> <string>svn</string> <key>SockType</key> <string>stream</string> </dict> </array> </dict> <key>inetdCompatibility</key> <dict> <key>Wait</key> <false/> </dict> </dict> </plist>

Now hit Escape and type ":wq". This saves the file and exits the editor.

creating home directory for SVN repositories

Now that you have enabled the deamon which runs whenever your machine is up (regardless whether you are logged in or not), you want to create the home directory for the user "_svn":
sudo mkdir /Users/Shared/svn

Also you want to make sure that only user _svn owns this directory, can read, write and execute things from this directory:
sudo chown -R _svn:_svn /Users/Shared/svn
sudo chmod -R ug+rwX,o= /Users/Shared/svn

Now it is a good time to reboot your machinei so the SVN server will be running.

creating repositories

Now suppose you want to create a repository named code_1, and import there a code from your directory ~/code_1/. For this you will do the following:

  • Goto the directory your files are at
    cd ~/code_1
  • Create the directory for the code in your SVN home directory. You want to do this as a user _svn and give the absolute path as an argument:
    sudo -u _svn svnadmin create /Users/Shared/svn/code_1
  • Import your files in the repository:
    sudo svn import file:///Users/Shared/svn/code_1 -m"Initial import"
    Write your commit file as prompted. At this point your code should be imported into the repository. Note that you as a regular user cannot access the repository since you have granted ownership and permissions to the user _svn earlier. If you want to view the contents of the repository, you will have to log on as root.

To check whether your SVN server is running, go to a temporary directory (e.g., cd ~/tmp/) and type
svn co svn://(insert your computer name here)/code_1
You should see a checked out version of your code in the directory code_1.

Certainly, you would like to host multiple code repositories (that is, more than one code). Just repeat the steps above for every new code you decide to use SVN for.

A list of useful things to do after this would be

  1. Configure your repository access permissions (users, passwords, etc.)
  2. Think about the access euthentication and encription (Apache, SSH, SSL, etc.)
All of these are thoroughly covered in the online SVN Manual in the Chapter 6, Server Configuration.

using Apache webserver and SVN

There are several reasons to use Apache module instead of the standalone SVN server. Some of those are:

  1. It does not require you to open the custom SVN port (port 3690). All communications are handled by Apache via standard HTTP and HTTPS ports (ports 80 and 443). This is beneficial for users that are behind some external firewalls that block all custom ports.
  2. Apache has good authentication mechanisms built into it.
  3. Your SVN repositories become accessible via WWW. With some minor additions you can run something very similar to Google Codes.

If you run SVN with Apache authentication using HTTPS protocol, you need to change the ownership of the repositories to the user _www &mdash it is also created automatically in OS X Leopard. Then creation of your repository requires the following steps.

Go to the directory where you code is at, then type

sudo -u _www svnadmin create /Users/Shared/svn/(repository name)
svn import https://( name) -m"Initial import"

For the rest, see the link from the list here

Copyright © 2009 Sergei Chumakov
Last modified Jul 28 2010 16:29

Accessed 5478 times