Running an SVN Server Automatically in the Background

Starting svnserve from the Terminal as described in Setting up an SVN Server is easy enough, but you will have to do this each time you restart your computer. This section describes how to configure your Mac such that this is done automatically for you.

This section assumes that you are familiar with using the Terminal.

Please be aware that by following these instructions you will be permanently changing your Mac’s configuration.

This information is provided for your convenience. You do this at your own risk. Zennaware accepts no responsibility for any issues resulting from changes you make to your system’s configuration.

Create a launchd Property List File

macOS includes a component called launchd which manages apps that run in the background. The steps outlined here describe how to configure launchd to run svnserve on demand to process each incoming request from a Subversion client.

  1. You need to know where svnserve is installed on your Mac before continuing. Open the Terminal and enter:

    which svnserve

    Make a note of the path output by this command. By default it will output:

    /usr/bin/svnserve

  2. Next, create a text file with the following contents and save it as org.tigris.subversion.svnserve.plist in /Library/LaunchDaemons

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
        "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
        <dict>
            <key>Disabled</key>
            <false/>
            <key>UserName</key>
            <string>_svn</string>
            <key>Label</key>
            <string>org.tigris.subversion.svnserve</string>
            <key>ProgramArguments</key>
            <array>
                <string>/usr/bin/svnserve</string>
                <string>--inetd</string>
            </array>
            <key>ServiceDescription</key>
            <string>SVN Version Control System</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>
  3. If svnserve is not located at /usr/bin/svnserve on your Mac then change the path on line 14:

    <string>/path/to/svnserve</string>

  4. This script will run svnserve as the built-in _svn user. You will need to ensure that _svn has write access to your repository by entering the following command into the Terminal:

    chown -R _svn /path/to/repository

    Alternatively, you can change the user on line 9, e.g.:

    <string>zoe</string>

    This will run svnserve as zoe.

  5. You can also specify the --root argument (described in the previous section) by adding the following 2 lines to the ProgramArguments section:

    <string>--root</string>
    <string>/path/to/repository</string>

Starting the Daemon

Instruct launchd to load the contents of the file and start listening for incoming requests by entering the following commands:

sudo launchctl load \
  /Library/LaunchDaemons/org.tigris.subversion.svnserve.plist

sudo launchctl start \
  org.tigris.subversion.svnserve

You will be prompted to enter your password. The Terminal’s shell must be running as a user with administrator rights.

launchd should now automatically start listening for incoming requests each time you restart your Mac.

Stopping The Daemon

To stop listening for requests and unload the configuration, enter the following commands:

sudo launchctl stop \
  org.tigris.subversion.svnserve
	
sudo launchctl unload \
  /Library/LaunchDaemons/org.tigris.subversion.svnserve.plist

For more information on svnserve, refer to the Subversion documentation included with Cornerstone (Help > Subversion Documentation).