首页 > Web开发 > 详细

启动脚本---》httpd,nginx

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

#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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!