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 
相关推荐
SelectDB6 小时前
驾驭 CPU 与编译器:Apache Doris 实现极致性能的底层逻辑
运维·数据库·apache
鲨莎分不晴18 小时前
大数据的“大动脉”:深度剖析 Apache Kafka 的高性能之道
大数据·kafka·apache
oMcLin18 小时前
如何在 RHEL 7 上通过配置 Apache Kafka 集群的分区机制,提升消息传递系统的吞吐量与数据流处理能力?
分布式·kafka·apache
鲨莎分不晴18 小时前
给 Hadoop 插上 SQL 的翅膀:Apache Hive 架构与实战全解
hadoop·sql·apache
oMcLin18 小时前
如何在CentOS 8上配置并调优Apache Spark集群,确保大规模数据分析任务的高效运行与资源分配?
spark·centos·apache
SelectDB1 天前
从 Greenplum 到 Doris:集群缩减 2/3、年省数百万,度小满构建超大规模数据分析平台经验
数据库·数据分析·apache
それども2 天前
Apache POI XSSFWorkbook 和 SXSSFWorkbook 的区别
apache·excel
xifangge20253 天前
PHP 错误日志在哪里看?Apache / Nginx / PHP-FPM 一次讲清
nginx·php·apache
潇凝子潇3 天前
Apache Kafka 跨集群复制实现方案
分布式·kafka·apache
大厂技术总监下海3 天前
数据湖加速、实时数仓、统一查询层:Apache Doris 如何成为现代数据架构的“高性能中枢”?
大数据·数据库·算法·apache