Shell篇之编写apache启动脚本

Shell篇之编写apache启动脚本

1. 脚本编写

vim apache_ctl.sh

#!/bin/bash

function_start(){
	printf "Starting Apaache  ...\n"
	/opt/lanmp/httpd/bin/apachectl start
}

function_stop(){
	printf "Stoping Apaache  ...\n"
	/opt/lanmp/httpd/bin/apachectl stop
}

function_restart(){
	printf "restarting Apaache  ...\n"
	/opt/lanmp/httpd/bin/apachectl restart
}

function_status(){
	apache_stat=0
	apache_tmpa=`ps -ef | grep http | grep root | grep -v grep | awk '{print $2}'`
	apache_tmpb=`cat /opt/lanmp/httpd/logs/httpd.pid`
	if [ `lsof -i:10068 | wc -l` -gt 0 ]; then
	  if [ `ps -ef | grep httpd | grep -v grep | wc -l` -gt 0 ]; then
	    if [[ $apache_tmpa -eq $apache_tmpb ]]; then
	       apache_stat=1
	    fi
	  fi
fi

if [ $apache_stat -eq 1 ]; then
  echo "apache(pid $apache_tmpa) is runing!"
elif [ $apache_stat -eq 0 ]; then
   echo "apache is not runing!"
fi
}

if [ "$1" = "start" ]; then
	function_start
elif [ "$1" = "stop" ]; then
	function_stop
elif [ "$1" = "restart" ]; then
	function_restart
elif [ "$1" = "status" ]; then
	function_status 
else
	printf "Usage: automate {start|stop|restart|status} \n"
fi

2. 赋权

chmod +x apache_ctl.sh

3. 命令

./apache_ctl.sh start
./apache_ctl.sh status
./apache_ctl.sh restart 
相关推荐
2407-2 shw6 小时前
Apache CVE-2021-41773 漏洞攻略
apache
游王子10 小时前
Apache APISIX学习(1):介绍、docker启动
学习·apache
沈艺强21 小时前
伊犁云计算22-1 apache 安装rhel8
apache
新知图书21 小时前
Apache的ab压力测试工具与性能监控
测试工具·apache
鸠摩智首席音效师21 小时前
如何配置 Apache 反向代理服务器 ?
apache
Hello.Reader1 天前
深入解析 Apache Doris架构、应用场景与最佳实践
大数据·架构·数据分析·apache
Apache Flink2 天前
Apache Flink 流批融合技术介绍
人工智能·flink·apache
程序员皮皮林3 天前
开源PDF工具 Apache PDFBox 认识及使用(知识点+案例)
java·pdf·开源·apache
前端-文龙刚3 天前
小程序给对象赋值(双向绑定)方法之一
服务器·小程序·apache