Home > Linux | CentOS, Subversion, cPanel > Install subversion on centos cpanel vps with autostart script on reboot

Install subversion on centos cpanel vps with autostart script on reboot

I learned this stuff by searching and want to add a quick reference here for others. To install subverion on CentOS, just do:

# yum install subversion

Make sure if “perl-URI” is installed or not. If its not there you can install it using

# yum install perl-URI

Now you may stuck here, because yum may not install perl-URI, why? If you have cpanel, probably you have added perl* to /etc/yum.conf exclude list. Just remove it and install perl-URI, then revert it.

The next thing was to create a repository.

# cd /home/username
# mkdir repos
# svnadmin create /home/username/repos/myProject1

I always create a symlink to make things easier:

# ln -s /home/username/repos /svn

Now to start subversion as daemon do:

# svnserve -d -r /svn

Ok, we need to setup subversion autostart at reboot. I just found a script sometime somewhere on internet and I do not really remember who was the author, but thanks to the guy, I edited the script to suit my needs. Below is the working result, I tested and installed it on CentOS x86_64

#!/bin/bash
#
#   /etc/rc.d/init.d/subversion
#
# Starts the Subversion Daemon
#
# chkconfig: 345 90 10
# description: Subversion Daemon

# processname: svnserve

source /etc/rc.d/init.d/functions

[ -x /usr/bin/svnserve ] || exit 1

# To pass additional options (for instace, -r root of directory to server) to
# the svnserve binary at startup, set OPTIONS here.
#
OPTIONS=”-r /svn”
RETVAL=0
prog=”svnserve”
desc=”Subversion Daemon”

start() {
        echo -n $”Starting $desc ($prog): ”
   daemon $prog -d $OPTIONS
   RETVAL=$?
   [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
   echo
}

stop() {
   echo -n $”Shutting down $desc ($prog): ”
   killproc $prog
   RETVAL=$?
   [ $RETVAL -eq 0 ] && success || failure
   echo
   [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog
   return $RETVAL
}

case “$1″ in
  start)
   start
   ;;
  stop)
   stop
   ;;
  restart)
   stop
   start
   RETVAL=$?
   ;;
  condrestart)
        [ -e /var/lock/subsys/$prog ] && restart
   RETVAL=$?
   ;;
  *)
   echo $”Usage: $0 {start|stop|restart|condrestart}”
   RETVAL=1
esac

exit $RETVAL

Save this script on /etc/init.d/subversion and make it chmod 0750
Execute /etc/init.d/subversion and make sure it does not have any error.
To make it autostart at reboot time, we should use chkconfig facility on RedHat/CentOS.

# chkconfig –level 345 subversion on

To get more info on chkconfig see man chkconfig and man runlevel, and http://en.wikipedia.org/wiki/Run_level

Now reboot vps / server and check it works. Yes, it was so easy, no? ;)

  1. June 27th, 2008 at 00:44 | #1

    Hi,
    Thanks for the info. This is exactly what I was looking for. However, I think your last command has a typo. Shouldn’t it be “chkconfig –level 345 subversion on”? Also, as opposed to restarting the whole VPS, just run “service subversion restart” to test.
    Thanks again,
    Brady

  2. Mark
    April 14th, 2009 at 02:20 | #2

    Hi,
    Great post, worked like a charm. I noticed though:
    a) May need to update the path to the subversion repository root directory (the -r option) as applicable
    b) Shouldn\’t the \’r\’ option be prefixed with – i.e. -r /svn ?
    c) When pasting the script into a text editor look out for odd quotes. The \

  3. Roman Safonov
    July 27th, 2009 at 21:14 | #3

    Hi,
    Really helpful!
    Brady is right: service subversion restart OR /etc/init.d/subversion restart checks the script.

    Thanks!

  1. September 4th, 2010 at 12:47 | #1