#!/bin/bash # # author:liusha # description: SVN Server start|stop|restart|status. USER=root HOME=/home/svn SERVER_NAME="SVN Server" pid=0 #获取进程号 getPid() { pid=`ps -ef |grep svnserve |grep -v "grep" |awk '{print $2}'` } #启动服务 start() { getPid if [ ! -n "$pid" ]; then SVN_CMD="svnserve -d -r $HOME" echo "$SERVER_NAME Start-----------------" su $USER -c "$SVN_CMD" echo "$SERVER_NAME Finish----------------" else echo "$SERVER_NAME is runing PID: $pid" fi } #停止服务 stop() { getPid if [ ! -n "$pid" ]; then echo "$SERVER_NAME not runing" else echo "$SERVER_NAME stop..." kill -9 $pid fi } #重启服务 restart() { stop sleep 1s start } #服务状态 status() { getPid if [ ! -n "$pid" ]; then echo "$SERVER_NAME not runing" else echo "$SERVER_NAME is runing PID: $pid" fi } case $1 in start) start ;; stop) stop ;; restart) restart ;; status) status ;; *) echo "$0: Usage: $0 {start|stop|restart|status}" exit 1 ;; esac