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 
相关推荐
王锋(oxwangfeng)14 小时前
Apache Flink 在 Kubernetes 上的高效部署与优化实践
flink·kubernetes·apache
小天源19 小时前
银河麒麟操作系统 V10安装Apache Tomcat
apache
自可乐19 小时前
Apache Airflow完全学习指南:从入门到精通的系统教程
人工智能·机器学习·apache
Hello.Reader19 小时前
Apache Flink 网络 Buffer 调优Debloating 的边界、Buffer 生命周期
大数据·flink·apache
Hello.Reader19 小时前
Apache Flink 内存故障排查从 IllegalConfigurationException 到 OOMKilled,一篇把坑踩平的指南
大数据·flink·apache
小宇的天下2 天前
Cadence allegro---assign net
服务器·php·apache
软件派3 天前
Apache Paimon终极教程——流批一体存储引擎深度解析(附Flink集成案例+性能调优代码)
apache·性能调优·流批一体·实时数据处理·paimon教程·flink集成·湖仓架构
三水不滴3 天前
Apache RocketMQ的原理与实践
经验分享·apache·rocketmq
whale fall3 天前
celery -A tool.src.main worker --loglevel=info --queues=worker1_queue & 什么意思
python·学习·apache
TracyCoder1234 天前
ElasticSearch核心引擎Apache Lucene(五):相关性算分 (Scoring)
elasticsearch·apache·lucene