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 
相关推荐
penngo13 小时前
FlowLoom:基于 Apache Spark 的可视化数据处理平台
大数据·spark·apache
Apache RocketMQ2 天前
全新 AI 消息模型:Apache RocketMQ 如何让 AI 应用拥抱事件驱动架构?
人工智能·apache·rocketmq
MageGojo2 天前
给起名工具接入八字起名 API:参数设计、JSON 示例和应用场景
json·apache
x***r1512 天前
linux安装 apache-tomcat-7.0.42.tar.gz 详细步骤(解压、配置、启动)
linux·tomcat·apache
阿里云云原生3 天前
Apache RocketMQ 5.5.0 发布:LiteTopic 深度解析,如何支撑百万级 AI 会话并发?
apache·rocketmq
清平乐的技术专栏4 天前
【Doris从零到一】(一)Apache Doris 概述
apache
RestCloud4 天前
开源vs商业iPaaS:Apache Camel、MuleSoft与RestCloud的正面交锋
开源·apache·ipaas·mulesoft·api管理·集成平台
Volunteer Technology4 天前
集群基础环境搭建(一)
大数据·apache
Volunteer Technology5 天前
集群基础环境搭建(二)
大数据·flink·apache
杨云龙UP6 天前
Linux 根分区被日志吃满?一次 58G Broker 日志清理实战_2026-05-20
linux·运维·服务器·数据库·hdfs·apache