Apr 122012
 

SVN을 RPM으로 설치하면 시스템 재시작시 실행해주는 스크립트가 들어가 있지 않다.
이런 경우 대부분 /etc/rc.d/rc.local 에 넣어서 처리를 하는 경우가 대부분인데. 이번에 설치한 CentOS 서버에서는 /etc/rc.d/rc.local 이 제대로 작동하지 않아서 스크립트를 찾아보니 없어서 하나 만들었다.

#!/bin/bash
#
# svnserve        Startup SVN Server
#
# chkconfig: - 85 15
# processname: svnserve
# config: none
# pidfile: /var/run/svnserve.pid
 
# Source function library.
. /etc/rc.d/init.d/functions
 
# Path to the apachectl script, server binary, and short-form for messages.
svnserve=/usr/bin/svnserve
prog=svnserve
pidfile=/var/run/svnserve.pid
logfile=/var/log/svnserve
repository=/home/svn
OPTIONS="-d -r $repository --pid-file $pidfile --log-file $logfile"
RETVAL=0
 
start() {
        echo -n $"Starting $prog: "
        daemon --pidfile=${pidfile} $svnserve $OPTIONS
        RETVAL=$?
        echo
        return $RETVAL
}
 
stop() {
        echo -n $"Stopping $prog: "
        killproc -p ${pidfile}
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && rm -f ${pidfile}
}
 
# See how we were called.
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  restart)
        stop
        start
        ;;
  *)
        echo $"Usage: $prog {start|stop|restart}"
        RETVAL=2
esac
 
exit $RETVAL

위와 같은 파일을 /etc/init.d/svnserve 로 생성을 하고, 아래와 같이 서비스 등록을 해주면 된다.

[root@localhost ~]# chmod 755 /etc/init.d/svnserve
[root@localhost ~]# chkconfig --add svnserve 
[root@localhost ~]# /sbin/runlevel
N 3
[root@localhost ~]# chkconfig --level 3 svnserve on

참고로 데스크탑으로 설정한 경우에는 Run Level에 5이므로 level을 5로 설정해야 한다.

아래와 같이 사용을 하면 된다.

[root@localhost log]# /etc/init.d/svnserve stop
svnserve 를 정지 중:                                       [  OK  ]
[root@localhost log]# /etc/init.d/svnserve start
svnserve (을)를 시작 중:                                   [  OK  ]
[root@localhost log]# /etc/init.d/svnserve restart
svnserve 를 정지 중:                                       [  OK  ]
svnserve (을)를 시작 중:                                   [  OK  ]
[root@localhost log]#
Plugin from the creators of Brindes :: More at Plulz Wordpress Plugins