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 
相关推荐
前端玖耀里20 小时前
Spring Boot 3 集成 Apache Calcite:多数据源查询的终极解决方案
spring boot·后端·apache
你才是臭弟弟3 天前
Apache Flink+Apache Iceberg(协作关系)
大数据·flink·apache
SelectDB技术团队4 天前
构建 AI 数据基座:思必驰基于 Apache Doris 的海量多模态数据集管理实践
人工智能·apache·知识图谱
你才是臭弟弟4 天前
Apache Iceberg+Apache Flink(安装流程)
大数据·flink·apache
你才是臭弟弟4 天前
Apache Iceberg核心特征
大数据·apache
沉默-_-5 天前
微信小程序页面配置详解
学习·微信小程序·apache·微信开发者工具
SeaTunnel5 天前
Apache SeaTunnel MySQL CDC 支持按时间启动吗?
大数据·数据库·mysql·开源·apache·seatunnel
weixin_462446236 天前
Java 使用 Apache Batik 将 SVG 转换为 PNG(指定宽高)
java·apache·svg转png
学习3人组6 天前
Apache Superset开源现代化数据BI工具
开源·apache
SelectDB技术团队6 天前
AI 能力揭秘(五):Apache Doris 原生向量检索的设计及实现
人工智能·apache