svn 启动服务脚本(shell)

#!/bin/bash
#SVN Executor Path
svn_path='/usr/bin/svnserve'
#SVN startup parameters
port='8888'
root_path='/svn'
pid_file='/var/run/svn.pid'
log_file='/var/log/svn.log'
listen=`netstat -antp | grep -cE 'listen|svnserve'`
pid=`netstat -antp | grep -E 'svnserve|listen' | awk '{print $NF}' | sed 's/\/.*//g'`

#Service started but no PID file, create PID file function
pid_fun() {
        echo "SVN service started but no PID file was found"
        echo "----------Creating PID file for you----------"
        sleep 2 && echo $pid > $pid_file
        echo "The PID file was created successfully PID is `cat $pid_file`"
}

#-----------------Start SVN-------------------
svn_start() {
	if [ $listen -eq 1 ];then
		if [ -e $pid_file ];then
			echo "SVN service started PID is `cat $pid_file`"
		else
			pid_fun
		fi
	else
		$svn_path -d -r $root_path --listen-port $port --pid-file $pid_file --log-file $log_file	
		if [ $? -eq 0 ];then
			echo "SVN service started successfully PID is `cat $pid_file`"
		else
			echo "SVN service startup failed"
		fi
	fi
}

#-----------------Stop SVN-------------------
svn_stop() {
		kill -9 $pid
		echo "SVN service is down"
}

#-----------------Status SVN-------------------
svn_status(){
	if [ $listen -eq 1 ];then
		if [ -e $pid_file ];then
			echo "SVN service is running..... PID is `cat $pid_file`"
		else
			pid_fun
		fi
	else
		echo "SVN service is not running"
	fi
}

case "$1" in
	start)
		svn_start
	;;
	stop)
		svn_stop
	;;
	status)
		svn_status
	;;
	*)
		echo "Usage: $0 {start|stop|status}"
esac

猜你喜欢

转载自blog.csdn.net/qq_31755183/article/details/85680346