Tutorial: Install and Configure Subversion 1.7 on CentOS 5

Tutorial: Install and Configure Subversion 1.7 on CentOS 5
By Shay Anderson on May 2013
In this simple tutorial I am going to walk you through installing Subversion 1.7 (or Subversion 1.6 if you don’t need Subversion 1.7) on CentOS 5 (in this tutorial I am installing Subversion on Cent OS 5.9).

Subversion Installation
First, if you don’t require Subversion 1.7, installing Subversion using command line is very easy: >> yum install subversionAt the time of writing this the default yum install of Subversion installs the Subversion 1.6 version. You can check what version yum will install by using command line: >> yum list available | grep subversion
If you want Subversion 1.7 installed (which is much better in my opinion than 1.6) you first have to download Subversion 1.7 from here: http://opensource.wandisco.com/centos/5/devel/RPMS/x86_64/.

If you already have Subversion installed and want to switch to Subversion 1.7 you can remove Subversion with: >> yum remove subversion*
Here is an example of how to download and install Subversion 1.7: >> wget http://opensource.wandisco.com/centos/5/devel/RPMS/x86_64/subversion-1.7.9-1.x86_64.rpm /home/tmpNow, install the package: >> rpm -ivh /home/tmp/subversion-1.7.9-1.x86_64.rpmFinally, check version and you should see something like this: >> svn –version
svn, version 1.7.9 (r1462340)
compiled Mar 29 2013, 19:59:15
Creating a Subversion Repository
Now we can setup a Subversion repository. First create a directory where the Subversion subversion repository(ies) can reside: >> mkdir /var/svnNow create Subversion repository: >> svnadmin create /var/svn/myrepoThen set correct user/group: >> chown -R myuser:myuser /var/svn/myrepoThen set correct permissions: >> chmod -R 755 /var/svn/myrepoNow your Subversion repository should look something like: myrepo
|– README.txt
|– conf
| |– authz
| |– passwd
| `– svnserve.conf
|– db
| |– current
| |– format
| |– fs-type
| |– fsfs.conf
| |– min-unpacked-rev
| |– rep-cache.db
| |– revprops
| | `– 0
| | `– 0
| |– revs
| | `– 0
| | `– 0
| |– transactions
| |– txn-current
| |– txn-current-lock
| |– txn-protorevs
| |– uuid
| `– write-lock
|– format
|– hooks
| |– post-commit.tmpl
| |– post-lock.tmpl
| |– post-revprop-change.tmpl
| |– post-unlock.tmpl
| |– pre-commit.tmpl
| |– pre-lock.tmpl
| |– pre-revprop-change.tmpl
| |– pre-unlock.tmpl
| `– start-commit.tmpl
`– locks
|– db-logs.lock
`– db.lock
Subversion Server Configuration
Next, we need to make a global ‘svnserve.conf’ file for all repositories (this is the easiest way to do it in my opinion, but you can have separate ‘svnserve.conf’ files for each Subversion repository).

Copy ‘svnserve.conf’ from repository to /var/svn >> cp -v /var/svn/myrepo/conf/svnserve.conf /var/svnNow edit ‘/var/svn/svnserve.conf’: >> nano /var/svn/svnserve.confSo it looks something like: [general]
anon-access = none
auth-access = write
password-db = /var/svn/passwd
realm = My Subversion ServerNext, create backup copy of ‘svnserve.conf’: >> mv -v /var/svn/myrepo/conf/svnserve.conf /var/svn/myrepo/conf/svnserve.conf.BAKCreate symlink to svnserve.conf: >> ln -s /var/svn/svnserve.conf /var/svn/myrepo/conf/svnserve.conf
Create Subversion Users
Next, we need to create the users/passwords files: >> nano /var/svn/passwdAdd users/passwords so your file looks something like:[users]
shay = mypass
mike = hispassSave file and close, set permissions:>> chmod 644 /var/svn/passwd
Start the Subversion Server
We can now start the svnserve server: >> svnserve -dr /var/svn(-d option: daemon mode, -r option: root of directory to serve)

You can now test accessing the Subversion repository by checking out repository: >> svn checkout file:///var/svn/myrepo /home/myproj
Setting up Post Commit Hook
Finally, here is how to setup a Subversion hook that will auto update a project directory post commit: first, copy post-commit hook template file: >> cd /var/svn/myrepo/hooks
>> cp -v ./post-commit.tmpl ./post-commitMake hook executable: >> chmod +x ./post-commitThen edit the ‘./post-commit’ hook file so it looks something like:#!/bin/sh

sudo -u [shell user] /usr/bin/svn update /home/myproj –username [svn user] –password [svn password]Now you can test a commit and see if the update happens through the hook.

If you get an error like:”sudo: sorry, you must have a tty to run sudo”You can fix that error by editing ‘/etc/sudoers’ file and disabling (comment out) tty:#Defaults requiretty
Stopping the Subversion Server
First, find process ID of “svnserve -dr /var/svn”:>> ps -aux | grep svnWhich should give you results like:root 9292 0.0 0.0 80284 1152 ? Ss 11:18 0:00 svnserve -dr /var/svnNow you can kill process using: >> kill -9 9292The daemon ‘svnserve’ is no longer running.

Setting up Subversion Server to run on Server Boot
We can now setup a script that will auto start the Subversion server (svnserve) when the machine boots. First, create the ‘svnserve’ file in ‘/etc/init.d’: #!/bin/sh
# chkconfig: 2345 95 20
# description: svnserve {start|status|stop}
# processname: /etc/init.d/svnserve

# @file /etc/init.d/svnserve
# @author Shay Anderson 05.13

# repositories path
REPOS=/var/svn

# svnserve command
SVN=svnserve
SVN_OPT=”-dr”
SVN_DESC=”Subversion Server Daemon ($SVN)”

start() {
echo “Starting $SVN_DESC…”
$SVN $SVN_OPT $REPOS
echo “Done.”
echo
}

status() {
echo “$SVN_DESC status:”
ps -aux | grep “$SVN $SVN_OPT $REPOS”
echo
}

stop() {
echo “Stopping $SVN_DESC…”
pkill -f $SVN
echo
}

case “$1″ in
start)
start
;;
status)
status
;;
stop)
stop
;;
*)
echo “Usage: $0 {start|status|stop}”
echo
;;
esac

exit 1Make sure the file is executable: >> chmod +x /etc/init.d/svnserveNow you should be able to start, stop or restart the svnserve process by using this script: >> /etc/init.d/svnserve stop
>> /etc/init.d/svnserve start
>> /etc/init.d/svnserve status
Next, to set this script to run ‘start’ on server boot register the service: >> chkconfig –add /etc/init.d/svnserveNow, you can check if it is registered: >> chkconfig –list | grep svnserve
svnserve 0:off 1:off 2:on 3:on 4:on 5:on 6:offIf you ever want to remove the registered service use: >> chkconfig –del /etc/init.d/svnserve

The install and configuration of Subversion 1.7 on CentOS 5.9 is complete.

http://www.shayanderson.com/linux/tutorial-install-and-configure-subversion-1-7-on-centos-5.htm