Created
April 27, 2010 08:36
-
-
Save yeco/380498 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # | |
| # /etc/rc.d/init.d/subversion | |
| # | |
| # Starts the Subversion Daemon | |
| # | |
| #### | |
| # HOW TO USE: | |
| # | |
| # 1. grand execution permissions to the script: | |
| # [chmod a+x svnserve] | |
| # 2. add the svn listening port to the /etc/services file by adding: | |
| # [svnserve 3690/tcp # Subversion | |
| # svnserve 3690/udp # Subversion] | |
| # | |
| # 3. type in the following commands: | |
| # [chkconfig svnserve | |
| # service svnserve start] | |
| # | |
| # 4. check that the service is listening: | |
| # [netstat -anp | grep 3690] | |
| # | |
| # | |
| #### | |
| # 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 | |
| REPO_ROOT=/path/to/your/svnrepos | |
| #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 -r $REPO_ROOT --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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment