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 
相关推荐
南山丶无梅落15 小时前
文件上传漏洞1
apache·绕过·文件上传漏洞·网安·upload闯关·文件类型验证
kke_8816 小时前
电商/教育/工具类小程序,UV分析的3种不同思路
大数据·apache
nvd112 天前
深度解析:Apache Beam YAML 部署至 GCP Dataflow 的架构与最佳实践
架构·apache
27669582923 天前
拼多多m端/小程序 encrypt_info
java·小程序·apache·encrypt_info·encrypt_info解密·拼多多小程序·拼多多m端
ylscode3 天前
Apache CXF LDAP注入漏洞允许攻击者获取任意证书
apache
MageGojo6 天前
小程序每日一谜怎么做:riddle 接口接入示例
windows·小程序·apache·谜语
penngo7 天前
FlowLoom:基于 Apache Spark 的可视化数据处理平台
大数据·spark·apache
Apache RocketMQ8 天前
全新 AI 消息模型:Apache RocketMQ 如何让 AI 应用拥抱事件驱动架构?
人工智能·apache·rocketmq
MageGojo8 天前
给起名工具接入八字起名 API:参数设计、JSON 示例和应用场景
json·apache
x***r1519 天前
linux安装 apache-tomcat-7.0.42.tar.gz 详细步骤(解压、配置、启动)
linux·tomcat·apache