Thursday, 9 December 2010

Subversion Init script


소스 : http://mohanjith.net/blog/2007/07/svnserve-init-script.html

-------------------------------------------------------------------
/etc/rc.d/init.d/subversion 파일
-------------------------------------------------------------------

#!/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 asort(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

-------------------------------------------------------------------------------
/etc/sysconfig/subversion 설정 파일
-------------------------------------------------------------------------------


# Configuration file for the Subversion service

#
# To pass additional options (for instace, -r root of directory to server) to
# the svnserve binary at startup, set OPTIONS here.
#
#OPTIONS=
OPTIONS="--threads --root /var/svn" 



* options for the subversion deamon, such as '--root ', can be set in '/etc/sysconfig/subversion'
* run as root: 'chmod +x '/etc/init.d/subversion'
* run as root: 'chkconfig --add subversion && chkconfig subversion on'
* run as root: 'service subversion start' 

No comments:

Post a Comment