码迷,mamicode.com
首页 > Web开发 > 详细

启动脚本---》httpd,nginx

时间:2017-04-10 23:53:27      阅读:226      评论:0      收藏:0      [点我收藏+]

标签:启动脚本nginx httpd

#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

标签:启动脚本nginx httpd

原文地址:http://12346621.blog.51cto.com/12336621/1914679

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!