Summary: This article details how to setup svnserve to run as a Windows service. Running the server as a service makes it easy to monitor and manage the server from a remote Windows client and also allows the server to start automatically when the system boots.
To run svnserve as a Windows services you need Windows 2000/2003/XP or Vista and Subversion 1.4.0 or higher. For this article I used the version of svnserve that you can obtain by downloading the CollabNet Subversion server installer from openCollabNet, but these instructions should also work with versions of the executable that you build yourself or have obtained from other sources.
Versions of Subversion prior to 1.4.0 required that you use a 3 rd party program that acts as a service-aware wrapper to the svnserve executable. As of 1.4.0, however, the Subversion svnserve executable now has a new --service option that allows the server itself to respond to all of the required events in the Windows service lifecycle. Going forward, this is the preferred way to run svnserve as a service, and is the technique that I describe in this article.
Finally, before continuing, I would like to credit the source of information I used to write this article. As always, the book about Subversion that is maintained by the Subversion developers, Version Control with Subversion, has been invaluable in its role as the canonical reference for all information pertaining to Subversion. If you view the book online, be sure to reference the version that is labeled as containing content for 1.4 of Subversion so that you are viewing the text with the latest information.
The first step is to visit the download section on openCollabNet and grab the installer for the Windows server. The client installer does not contain the svnserve executable, so be sure to get the server installer. Run the installer, which will install the executables as well as add the installation folder to your PATH.
The next step is to open a Windows command prompt and create one or more repositories. Technically you can do this step later, or anytime in the process, but the article will flow better if we just do it now as shown in the following screen shot.
So what did I just do? The first step, which is not shown, is that I used the “CD \” command to get to the root of my C:\ drive. I then created a folder named “repositories” which will hold all of my repositories. I then ran the svnadmin command three times to create three repositories which I named “dev”, “mktg” and “docs” respectively. I only created multiple repositories to demonstrate that you can have multiple repositories that are all served from the single svnserve server instance. I leave it to you to decide how many repositories you will need. Obviously, you do need at least one, and consider that the name you give the repository will be exposed in the URL that your users use to access it. Generally, it is a very good idea to avoid using spaces in the repository name. Subversion will work with spaces, but they will need to be escaped as %20 when used in a URL.
Install as Service
Now that we have some repositories created, the next step is to install svnserve into Windows as a service. Windows includes a program named “sc.exe” that allows us to do this. On my Windows XP system, this program was already installed and in my PATH. To my knowledge it should be installed automatically on all Windows systems as it is just a component of Windows. To install svnserve as a service, you need to open a command prompt and run the command as shown:
If you would like to just cut and paste that command, here it is:
sc create svnserve binpath= "\"C:\Program Files\CollabNet Subversion Server\svnserve.exe\" --service -r C:\repositories" displayname= "Subversion Server" depend= Tcpip start= auto
Let me break down the elements in the command and explain them in more detail.
sc create svnserve
The first part of the command says that we are creating a service and that we want to give it an identifier of “svnserve”. You could use a different identifier if you prefer. The only time this name will matter is if you want to manage the service from the command line. For example the command “net start svnserve” can be used to start the service. In that example, the service identified by the name “svnserve” would be started.
binpath= "\"C:\Program Files\CollabNet Subversion Server\svnserve.exe\" --service -r C:\repositories"
This is the most important, and complicated, part of the command. It is telling Windows the name of the program to run when it starts the service as well as the arguments. Notice that there is some funky usage of double-quotes and escaping. Since the parameter value has spaces, the whole thing needs to be enclosed in double-quotes. In addition, since the path to the svnserve executable contains spaces, it also needs to be enclosed with double-quotes. However, since those double-quotes are inside of another set, they need to be escaped. So be sure to enter the command exactly as shown.
You have to include the --service option as an argument as that is what tells svnserve to respond to the Windows service life cycle events. You must NOT include any conflicting options such as --daemon (-d), --tunnel, or --inetd (-i). You can include additional options such as the -r option shown above. If you want to change the default port, you would want to include the --listen-port NNNN option as an argument.
displayname= "Subversion Server"
This value allows you to specify the name you will see for the service when working with the Services GUI in Windows. If you have embedded spaces in the name, be sure to enclose it all in double quotes as shown.
This value configures the service so that Windows does not attempt to start it until the TCP/IP service has started.
This value configures the service to start automatically when Windows starts.
Now that we have added the service, we could start it by running the command:
net start svnserve
Instead, let’s view the service in the Windows GUI and start it from there. The location of the Services application has moved around in various versions of Windows. It is generally available in the Administration Tools folder with the name “Services.”
This screen shot shows our service and that it is currently not started. First, double-click on the service so that we can see its details:
One of the aspects of the service you might want to change is on the Log On tab, which I am not going to show but will explain. By default, services run as a restricted system account. This is fine for svnserve and will work well. The exception might be if you want to use Subversion hook scripts in your repository. The hook scripts will run as the same user as the service and the default user is fairly limited. For example, it has no authority to access other systems on your network. If your scripts need those capabilities, you can use the Log On tab to change the service so that it runs as a user with the privileges you need to access your domain resources.
Click the Start button to start the service. If it fails to start the most likely problem is that you got the quotes escaping wrong on the command line. You will need to use the sc.exe program to remove and read the service or update the command line.
If you have a firewall running on your server, you might also need to open the port for svnserve so that it can listen on the port. The default port is tcp/3690.
Test the Server
Open the Windows command prompt and run the svn info command to verify that we can connect to the server.
In this example, I used the svn info command and gave it the URL to the repository I created and named “dev”. Note that the repository name is exposed in the URL, but not the on disk location (C:\repositories). I can access different repositories just by using a slightly different URL. The three repositories I created at the beginning would be accessed via these URL’s:
If you were running these commands from a different machine, you would need to specify the IP address or name of the server in place of localhost. If you used a different port than the default, by using the --listen-port option on the svnserve command, then you would need to include the port number in the URL:
Finally, the svnserve server is fairly dynamic. You should be able to create additional repositories as well as make changes to the configurations of existing repositories without needing to restart the service. It should recognize the changes immediately. In addition, now that the server is running as a service, besides ensuring that the server starts automatically when the system starts, it is also easy to script the stop and start of the server (using the net stop and net start commands) to accommodate your repository backup routines.
An area I did not touch on in this article is repository configuration. There are still things you need to do such as configure your users and passwords as well as the access rules. A good source of information on this is the Version Control with Subversion book I mentioned at the beginning of the article. The readme file included in the download of CollabNet Subversion also contains a quick walk though of the steps needed to configure your repository.
Finally, if you run into any problems or need some assistance in getting your repository configured correctly, be sure to visit the discussion forums that are available on openCollabNet. There are plenty of users available that are willing to provide you with assistance. Be sure to search the forums for answers as well. It is likely that someone else will have asked similar questions in the past, and it is good etiquette to look for those questions and answers before posting a new one. Of course there are also a number of services that are offered by CollabNet to help get you started and train you and your users on the best usage of Subversion.