shell脚本 http源码启动脚本

Apache启动脚本详解
本文提供了一个用于Apache服务器启动、停止、重启等操作的bash脚本示例。该脚本通过curl检查Apache服务状态,并使用wget模拟客户端请求验证服务是否运行。

源码包http启动脚本,仅供参考......下面有文本的。

wKioL1eknLPSlNa_AACfzTtFrdA523.pngwKiom1eknQnRwsIyAABSzjmbWVs440.pngwKioL1eknWzjBgHuAAAhUYvo-D8578.png

wKiom1eknceDTOfOAAATKdxbuwk621.png

#!/bin/bash

#Author: wangergui              Email:291131893@qq.com         Date:2016-06-01

#Function: source apache start script

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root:/bin

export PATH

[ -f /etc/rc.d/init.d/functions ] && . /etc/rc.d/init.d/functions || exit 2

APACHE=/usr/local/apache2/bin/apachectl

PIDFILE=/usr/local/apache2/logs/httpd.pid

CODE=$(curl -I -s http://localhost |awk 'NR==1 {print $2}')

function mystart () {

if [ ${CODE} -eq 200 -a -f ${PIDFILE} ];then 

   echo " httpd is aready running!"

 else

   rm -rf ${PIDFILE} && ${APACHE} && [ $? -eq 0 ] && echo "httpd start sucellfully!" || exit 3

fi


}

function mystop () {

wget -q http://localhost >/dev/null 2>&1

if [ $? -eq 0 -a -f ${PIDFILE} ];then

   killall -9 httpd 

   [ $? -eq 0 ] && echo "httpd stop ok"

 else

   rm -rf ${PIDFILE} && echo "httpd stop failed!"


fi

}

function myrestart () {


mystart

sleep 2

mystop



}

function myreload () {


wget -q http://localhost >/dev/null 2>&1


[ $? -eq 0 -f ${PIDFILE} ] && killall -s HUP ${APACHE} || exit 4


[ $? -ne 0 ] && echo "httpd service is not starting!"


}

function mystatus () {


wget -q http://localhost >/dev/null 2>&1


[ $? -eq 0 -a -f ${PIDFILE} ] && echo "httpd is running" || echo "httpd stop"



}

case $1 in


    "start")

           mystart

           ;;

                

    "stop")

           mystop

           ;;


    "restart")

           myrestart

           ;;


    "reload")

           myreload

           ;;


    "status")

           mystatus

           ;;


      "*")

          echo $"Usage: $0 {start|stop|restart|reload|status|}"

           exit 8

           ;;


esac



本文转自 wangergui 51CTO博客,原文链接:http://blog.51cto.com/wangergui/1834888,如需转载请自行联系原作者

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值