Friday, March 16, 2007

Subversion Server as Xinetd Service

Subversion has emerged as a popular versioning system. The subversion package ships with almost all Redhat flavours of Linux . The subversion server is run using the binary "svnserve" with appropriate arguments. I will mention a few of them here.

-r Directory : Specifies the root/base directory for all repositories.
-d : Run the server in daemon mode
-i : Run the server in inetd mode


What I usually do was to run "svnserve" in the daemon mode with a root directory specified, as follows:

[root@LinuxBox1 ~]#svnserve -r /home/repository -d

This will run as a standalone process all the time . This server is not accessed regularly, usually it is accessed only at the morning and evening of working days, when developers checkout and commit their projects. But svnserve is sitting there all the time consuming my valuable system resources. Another problem with this daemon mode is that I have to run the above command every time the machine restart, or have to put it in a start up script.


So I thought about a better alternative, to run it under xinetd service. The good thing about xinetd is that it will invoke svnserve only when necessary, thus consuming least system resources required, and I don't have to write separate start up script for svnserve.

All that is required to do is create a service file for svn(Even though the binary is svnserve, the service and subversion generally is called svn).

[root@LinuxBox1 ~]# vi /etc/xinetd.d/svn
#Subversion Server
#http://subversion.tigris.org/


service svn
{
socket_type = stream
wait = no
user = root
server = /usr/bin/svnserve
server_args = -r /home/repository -i
disable = no
}

# : Comments

socket_type : On what type of socket the service should listen. TCP(stream), UDP (dgram)

wait : How the server treats threads, a value of "yes" indicates that only a single connection will be managed by the service. If value is "no", a new server is started for each connection request.

user : The user identity under which the service will be started.

server : The binary used to start the service. To find out the path on your system, use:
[root@LinuxBox1 ~]#which svnserve
/usr/bin/svnserve

server_args : the arguments passed to the binary indicated by the option "server". Here, svnserve is run in inetd mode with /home/repository as the root

disable : Whether the service is enabled or disabled.

Save the file and restart the xinetd service.

[root@LinuxBox1 ~]#service xinetd restart

Svn by default listens on the port 3690. You can find out this in /etc/services.
[root@LinuxBox1 ~]#grep Subversion /etc/services
svn 3690/tcp # Subversion
svn 3690/udp # Subversion


Now to make sure that xinetd has invoked svnserve, check whether xinetd is listening on port 3690

[root@LinuxBox1 ~]# netstat -anp|grep 3690
tcp 0 0 0.0.0.0:3690 0.0.0.0:* LISTEN 30254/xinetd

As a final step to make sure that everything is working fine, checkout a project in this repository from another machine

[safeer@LinuxBox2 ~]$svn checkout --username safeer svn://linuxbox1/project1
Authentication realm: <svn://linuxbox1:3690
> Project 01 Repository
Password for 'safeer':
Checked out revision 0.

No comments:

Post a Comment