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 
相关推荐
Debug_TheWorld1 天前
Apache Flink 深度解析:流处理引擎的核心原理与生产实践指南
大数据·flink·apache
Apache IoTDB2 天前
Apache IoTDB V2.0.2/V1.3.4 发布|新增表模型权限管理、UDF、嵌套查询功能
apache·iotdb
ashane13142 天前
Apache PDFBox
apache
三次握手四次挥手2 天前
基于Python+Pytest实现自动化测试(全栈实战指南)
开发语言·python·自动化·k8s·apache·pytest·代码规范
自由如风7093 天前
Apache Atlas构建安装(Linux)
linux·运维·apache
techdashen3 天前
性能比拼: Nginx vs Apache
运维·nginx·apache
w23617346013 天前
解析三大中间件:Nginx、Apache与Tomcat
nginx·中间件·tomcat·apache
Minyy114 天前
使用注解方式整合ssm时,启动tomcat扫描不到resource下面的xxxmapper.xml问题,解决方法
java·spring boot·spring·apache·mybatis
斯普信专业组8 天前
二进制和docker两种方式部署Apache pulsar(standalone)
docker·容器·apache
架构文摘JGWZ9 天前
Apache Kafka UI :一款功能丰富且美观的 Kafka 开源管理平台!!
ui·kafka·开源·apache·工具