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 
相关推荐
Jackyzhe17 小时前
Apache Iceberg Variant 类型:v3 半结构化数据不再「二选一」
apache
Yeniden18 小时前
Java 后端从零到企业级:第1篇 Java 基础语法——变量、数据类型与运算符
java·开发语言·apache
盟道科技3 天前
电商小程序SKU数据模型设计:SPU、规格组合、库存与价格的工程实践
服务器·小程序·apache
A-刘晨阳3 天前
时序数据基础设施选型手册:Apache IoTDB 技术深度解析与性能实战
apache·iotdb
吴声子夜歌4 天前
ApacheCommons——commons-exec(外部进程与系统命令安全执行)
java·安全·apache
qetfw4 天前
Debian 部署 phpMyAdmin:Apache、PHP 与 MariaDB 管理界面配置
linux·debian·php·apache
吴声子夜歌4 天前
ApacheCommons——commons-compress(解压缩工具)
java·apache
吴声子夜歌4 天前
ApacheCommons——commons-math3(科学计算与线性代数)(一)
java·线性代数·算法·apache
吴声子夜歌4 天前
ApacheCommons——commons-configuration2(多数据源配置统一管理与热加载)
java·开发语言·算法·apache
W658034194 天前
Meta Muse Glimmer 30B开源深度拆解:Apache 2.0+投机解码,24GB显卡跑本地Agent
ai·开源·大模型·apache·deepseek