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 
相关推荐
Fireworkitte2 天前
Apache POI 详解 - Java 操作 Excel/Word/PPT
java·apache·excel
蚂蚁数据AntData2 天前
从性能优化赛到社区Committer,走进赵宇捷在Apache Fory的成长之路
大数据·开源·apache·数据库架构
小湘西2 天前
Apache HttpClient 的请求模型和 I/O 类型
java·http·apache
超级小忍12 天前
Spring Boot 集成 Apache Kafka 实战指南
spring boot·kafka·apache
天上掉下来个程小白14 天前
Apache ECharts-02.入门案例
前端·spring boot·apache·echarts·苍穹外卖
SelectDB技术团队15 天前
Apache Doris 3.0.6 版本正式发布
大数据·数据分析·apache·实时分析·极速分析
guygg8816 天前
Linux中的阻塞信号与信号原理
linux·mysql·apache
天上掉下来个程小白16 天前
Apache ECharts-01.介绍
前端·javascript·spring boot·apache·苍穹外卖
gb421528717 天前
高性能场景使用Protocol Buffers/Apache Avro进行序列化怎么实现呢
apache