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 
相关推荐
智_永无止境4 小时前
Apache Commons Math3 使用指南:强大的Java数学库
apache·math
一只 Lemon13 小时前
jquery 文件上传 (CVE-2018-9207)漏洞复现
apache
喜欢你,还有大家2 天前
Apache服务——搭建实验
apache
一休哥助手2 天前
Apache Thrift:跨语言服务开发的高性能RPC框架指南
网络协议·rpc·apache
Apache IoTDB2 天前
Apache IoTDB V1.3.5 发布|优化加密算法,优化内核稳定性,修复社区反馈问题
apache·iotdb
悠悠~飘2 天前
php学习(第四天)
php·apache
白鹭2 天前
apache实现LAMP+apache(URL重定向)
linux·运维·apache·url重定向·apache实现lamp架构
aramae2 天前
终端之外:解锁Linux命令行的魔法与力量
linux·服务器·apache
lifallen2 天前
Hadoop MapOutputBuffer:Map高性能核心揭秘
java·大数据·数据结构·hadoop·算法·apache
acaad3 天前
Apache Poi 实现导出excel表格 合并区域边框未完全显示的问题
spring·apache·excel