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 
相关推荐
SelectDB4 小时前
Apache Doris 实战教程:手把手实现 ClickHouse 表结构迁移与数据校验
apache
SelectDB4 小时前
Apache Doris 实战教程:从零搭建 MCP Server,让 AI Agent 直接用自然语言查数据
apache
SelectDB4 小时前
Apache Doris Segment V3 宽表优化实战教程:从建表到体验元数据按需加载
apache
java_logo10 小时前
Docker Compose 部署 Apache Superset:轻松搭建开源 BI 平台
docker·开源·apache·superset·轩辕镜像·superset部署方案·docker superset
Gent_倪1 天前
数据治理之元数据管理:Apache Atlas
apache
Kina_C1 天前
Apache HTTP Server 安装、配置与高级功能详解
linux·http·apache
中北marry2 天前
玄机靶场wp 第一章 日志分析-Apache日志分析
apache
java_logo2 天前
Apache Doris Docker 部署指南:实时分析数据库实战
数据库·docker·apache·doris·apache doris·轩辕镜像·docker部署doris
Zhu7582 天前
在k8s环境部署Apache Superset最新版
容器·kubernetes·apache
Zhu7582 天前
在k8s环境部署Apache zookeeper3.9.5,高可用,多pod
容器·kubernetes·apache