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 
相关推荐
SelectDB9 分钟前
宇信科技基于 SelectDB & Apache Doris 构建实时智能的银行经营分析平台
数据库·apache
SelectDB1 小时前
上海证券 SelectDB 升级实践:湖仓流批一体落地与 Elasticsearch 全面替换
数据库·apache
熊文豪16 小时前
工业物联网时序数据库选型指南:Apache IoTDB 的技术优势与应用实践
物联网·apache·时序数据库·iotdb
一个天蝎座 白勺 程序猿18 小时前
Apache IoTDB(10):数据库操作——从查询到优化的全链路实践指南
数据库·apache·时序数据库·iotdb
云计算老刘18 小时前
1.项目实战:LAMP-LNMP-分离部署
linux·mysql·php·apache·mariadb
SelectDB20 小时前
字节跳动:Apache Doris + AI 一站式融合数据引擎的探索与实践
数据库·apache
可涵不会debug1 天前
时序数据库选型指南:大数据时代下Apache IoTDB的崛起之路
大数据·apache·时序数据库
p***q781 天前
【保姆级教程】apache-tomcat的安装配置教程
java·tomcat·apache
SelectDB1 天前
Apache Doris 中的 Data Trait:性能提速 2 倍的秘密武器
数据库·后端·apache
0vvv02 天前
玄机靶场:第一章日志分析-apache日志分析
靶场·apache