SVN启动、停止、重启脚本

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

 

posted @ 2020-09-11 14:10  聚散彡流沙  阅读(676)  评论(0编辑  收藏  举报