Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Has any one got a init script for the svn service lying around that works?

Thanks

share|improve this question
up vote 0 down vote accepted

Here is what i cooked up. note my svn directory is on the root folder /svn

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

# processname: svnserve

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

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

RETVAL=0
prog="svnserve"
desc="Subversion Daemon"

start() {
        echo -n $"Starting $desc ($prog): "
   daemon $prog -r /svn -d
   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

Change this line to reflect your directory

daemon $prog -r /svn -denter code here

Then run in shell

#chkconfig --add svnserve
#chkconfig svnserve on

Restart the service to see if it works

#service svnserve restart

and boom :D

share|improve this answer

I've created a intelligent debian script based mainly on Tomcat package. You can change the main variable if needed, It can handle default mechanizm also. Enjoy.

#! /bin/sh
#
# /etc/init.d/subversion -- startup script for Subversion
#
# Author: Csaba Tenkes csaba.tenkes@brevissimus.eu
#
### BEGIN INIT INFO
# Provides:          subversion
# Required-Start:    $local_fs $remote_fs $network
# Required-Stop:     $local_fs $remote_fs $network
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start subversion
# Description:       Start the Subversion server.
### END INIT INFO

set -e
PATH=/bin:/usr/bin:/sbin:/usr/sbin
DESC="Subversion server"
NAME=svnserve
SCRIPTNAME=/etc/init.d/$NAME
PIDFILE=/var/run/$NAME.pid

SVN_USER=subversion
SVN_GROUP=subversion
SVN_REPO_PATH=/opt/svn-repos/

SVNSERVE=/usr/bin/$NAME
SVNSERVE_ARGS="-d -r $SVN_REPO_PATH"

[ -x "$SVNSERVE" ] || exit 0

[ -r /etc/default/$NAME ] && . /etc/default/$NAME

. /lib/lsb/init-functions


case "$1" in
  start)
    set +e
    log_daemon_msg "Starting $DESC" "$NAME"
    if ! [ -f "$PIDFILE" ];  then # TODO: 'ps fax | grep svnserve| grep ?' or process is existing
        umask 002
        start-stop-daemon --start --chuid $SVN_USER:$SVN_GROUP --make-pidfile --pidfile $PIDFILE --exec $SVNSERVE -- \
            $SVNSERVE_ARGS >/dev/null; 
        chown $SVN_USER "$PIDFILE" 
        log_end_msg 0
    else    
        log_progress_msg "(already running)"
        log_end_msg  $?
    fi
    set -e
    ;;

  stop)
    set +e
    log_daemon_msg "Stopping $DESC" "$NAME"
    if [ -f "$PIDFILE" ]; then 

        if start-stop-daemon --stop --exec $SVNSERVE; then
            log_end_msg 0
        else
            log_end_msg $?
        fi  
        rm -f "$PIDFILE"
    else
        log_progress_msg "(not running)"
        log_end_msg 0
    fi  
    set -e
    ;;

  restart|force-reload)
    if [ -f "$PIDFILE" ]; then
        $0 stop
        sleep 1
    fi
    $0 start
    ;;

  status)
    set +e
    start-stop-daemon --test --start --pidfile "$PIDFILE" \
    --user $SVN_USER --exec $SVNSERVE \
    >/dev/null 2>&1

    if [ "$?" = "0" ]; then
        if [ -f "$PIDFILE" ]; then
            PID=`cat $PIDFILE`
            log_daemon_msg "$DESC" "$NAME (pid $PID) is running.."
            log_end_msg 0
            exit 0
        else
            log_daemon_msg "$DESC" "$NAME is not running"
            log_end_msg 0
            exit 3
        fi
    else
        log_daemon_msg "$DESC " "$NAME is running with pid `cat $PIDFILE`"
        log_end_msg 0
        exit 0
    fi
    set -e
    ;;


  *)
    log_success_msg "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}"
    exit 1
    ;;
esac

exit 0
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.