啓動腳本---》httpd,nginx

#vim httpd.sh

#!/bin/bash
#chkconfig: - 45 55
httpd=/usr/sbin/httpd
pid=/var/run/httpd/httpd.pid
start(){
     if [ -f $pid ];then
        echo 已經啓動
        exit
     fi
      echo "starting......"
     $httpd
     if [ $? -ne 0 ];then
        echo "啓動失敗...."
     else
         echo    "ok"
      fi
 }
stop(){
    if [ ! -f $pid ];then
       echo 已經關閉
       exit
      fi
       echo "已經關閉....."
      if [ -f $pid ];then
       kill `cat $pid`
         echo "關閉成功..."
      else
         echo  "本來就關閉...."
      fi
}  
status(){
     if [ -f $pid ];then
        echo "staring...."
     else
          echo "已經關閉...."
     fi
}
restart(){
       if [ -f $pid ];then
          echo "已經重啓"
       else
         $httpd
         fi
}

case $1 in

start)
     start;;
stop)
     stop;;
status)
     status;;
restart)
     restart;;
*)
  echo "用法是$0 { start|stop|restart|status}"
  esac   





#vim nginx.sh

#!/bin/bash
#chkconfig: - 44 55
nginx=/usr/sbin/nginx
pid=/usr/local/nginx/logs/nginx.pid
start(){
       if [ -f $pid ];then
           echo "已經啓動"
           exit
       fi
           echo "starting......"
           $nginx
        if [ $? -ne 0 ];then
            echo "啓動失敗...."
        else
            echo "啓動成功"
        fi
}
stop(){
        if [ ! -f $pid ];then
            echo "已經關閉..."
            exit
        fi
            echo "已經關閉..."

if [ -f $pid ];then
            kill `cat $pid`
            echo "關閉成功..."
        else
            echo "本來就關閉....."
        fi
}
status(){
        if [ -f $pid ];then
            echo "start....."
        else
            echo "已經關閉..."
        fi
}
restart(){
        if [ -f $pid ];then
            echo "已經重啓"
        else
            $nginx
        echo "重啓成功"
        fi
}
case $1 in
start)
    start;;
stop)
    stop;;
status)
   status;;
restart)
   restart;;
*)
echo "用法是$0 {start|stop|restart|status}"
esac



#sh nginx.sh stop

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章