首页 > 代码库 > 启动脚本---》httpd,nginx

启动脚本---》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

本文出自 “12336621” 博客,请务必保留此出处http://12346621.blog.51cto.com/12336621/1914679

启动脚本---》httpd,nginx