[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Subversion Init script

From: S.H.Mohanjith <moha_at_mohanjith.net>
Date: 2007-07-31 07:57:56 CEST

Hi,

I have attached an Init script for subversion. The script should be
placed in /etc/init.d/. You could use the script to start, stop,
restart, condrestart, and forcestop the svnserve as a daemon and also
check the status of the daemon. It will use a pid file to store pid in
order to kill the svnserve daemon.

This was tested on fc6 running kernel 2.6.20-1.2962.fc6. Subversion
1.4.2 (subversion-1.4.2-2.fc6).

Init script is something that I missed in svnserve. I use a local svn
servers for my personal projects and it was annoying to start the
service everytime I had shutdown the machine. Also I didn't want to
just add it such that it starts at the startup without init.

I hope this script will become a part of svn. This will encourage the
users like me who don't have a dedicated server hardware but would like
to use svn.

Many thanks for a such a wonderful version control system. 8-)

Also I would like to join subversion development. I can contribute at
least 5h a week. I'm fluent in PHP and Shell scripting and can code in
C++.

I didn't get the chance to test on many distros. :-(
I would like to correct any portability issues, let me know if there are
any.

Please let me know if there are any other issues in the Init script as well.

Cheers,
Mohanjith

PS:
1. There is an option to stop even an svn daemon not started by the
     script(forcestop).

2. For more information see my blog at
     http://blog.mohanjith.net/2007/07/svnserve-init-script.html

#!/bin/bash
#
# /etc/rc.d/init.d/subversion
#
# Starts the Subversion Daemon
#
# chkconfig: 2345 90 10
# description: Subversion Daemon
# processname: svnserve
# pidfile: /var/lock/subsys/svnserve

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

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

### Default variables
SYSCONFIG="/etc/sysconfig/subversion"

### Read configuration
[ -r "$SYSCONFIG" ] && source "$SYSCONFIG"

RETVAL=0
prog="svnserve"
desc="Subversion Daemon"
pidfile="/var/run/$prog.pid"

start() {
   echo -n $"Starting $desc ($prog): "
   daemon $prog -d $OPTIONS --pid-file $pidfile
   RETVAL=$?
   if [ $RETVAL -eq 0 ]; then
     touch /var/lock/subsys/$prog
   fi
   echo
}

obtainpid() {
   pidstr=`pgrep $prog`
   pidcount=`awk -v name="$pidstr" 'BEGIN{split(name,a," "); print length(a)}'`
   if [ ! -r "$pidfile" ] && [ $pidcount -ge 2 ]; then
        pid=`awk -v name="$pidstr" 'BEGIN{split(name,a," "); print a[1]}'`
        echo $prog is already running and it was not started by the init script.
   fi
}

stop() {
   echo -n $"Shutting down $desc ($prog): "
   if [ -r "$pidfile" ]; then
        pid=`cat $pidfile`
        kill -s 3 $pid
        RETVAL=$?
   else
        RETVAL=1
   fi
   [ $RETVAL -eq 0 ] && success || failure
   echo
   if [ $RETVAL -eq 0 ]; then
     rm -f /var/lock/subsys/$prog
     rm -f $pidfile
   fi
   return $RETVAL
}

restart() {
        stop
        start
}

forcestop() {
   echo -n $"Shutting down $desc ($prog): "

   kill -s 3 $pid
   RETVAL=$?
   [ $RETVAL -eq 0 ] && success || failure
   echo
   if [ $RETVAL -eq 0 ]; then
     rm -f /var/lock/subsys/$prog
     rm -f $pidfile
   fi

   return $RETVAL
}

status() {
   if [ -r "$pidfile" ]; then
        pid=`cat $pidfile`
   fi
   if [ $pid ]; then
           echo "$prog (pid $pid) is running..."
   else
        echo "$prog is stopped"
   fi
}

obtainpid

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

exit $RETVAL

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Tue Jul 31 07:56:34 2007

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.