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 
相关推荐
Suchadar19 小时前
源码编译Apache
apache
一字白首1 天前
小程序组件化进阶:从复用到通信的完整指南DAY04
前端·小程序·apache
专注_每天进步一点点2 天前
mysql-connector-j(8.0 及以上版本,包括你使用的 8.3.0)并非采用 GPL 许可证,因此你在项目中引入该依赖时,不需要遵循 GPL 的开源要求(比如开源你的整个项目)
数据库·mysql·apache
不爱学英文的码字机器2 天前
Apache RocketMQ+cpolar 让消息服务全网可达
apache·rocketmq
鸽芷咕2 天前
海量时序数据选型指南:从大数据架构演进看 Apache IoTDB 的崛起
大数据·数据库·架构·apache
D愿你归来仍是少年3 天前
Apache Spark 第 3 章:核心概念 RDD / DataFrame
大数据·spark·apache
D愿你归来仍是少年3 天前
Apache Spark 第 4 章:Spark 整体架构
spark·apache
D愿你归来仍是少年3 天前
Apache Flink 算子(Operator)深度解析
大数据·flink·apache
可涵不会debug3 天前
时序数据库选型指南:Apache IoTDB——大数据时代的优选方案
apache·时序数据库·iotdb
yumgpkpm3 天前
Apache Spark 和 Flink,处理实时大数据流对比(Cloudera CDH、CDP)
flink·spark·apache