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 
相关推荐
程序猿乐锅1 天前
【苍穹外卖 day11|统计报表接口与 Apache ECharts 图表展示】
前端·apache·echarts
硬核科技牛2 天前
AI生成的小程序,数据能导出换平台吗
小程序·apache
观远数据3 天前
连锁零售的BI落地清单:从门店日报到智能补货的6步推进路径
apache·零售
似璟如你3 天前
IoTDB 从零入门:安装、部署与第一个时序数据写入(Windows版本)
apache·时序数据库·iotdb
DolphinScheduler社区4 天前
Apache DolphinScheduler “僵尸任务”怎么处理?新旧版本安全清理方案
apache·海豚调度·大数据工作流调度
川石课堂软件测试5 天前
安全测试|SQLMap渗透扫描工具
python·功能测试·测试工具·mysql·单元测试·tomcat·apache
Zhu7585 天前
在k8s环境部署Apache Kafka 集群架构,combined模式,无SSL配置
kafka·kubernetes·apache
Zhu7585 天前
在k8s环境部署Apache kafka4.3.1
容器·kubernetes·apache
qq_163135755 天前
Apache NIFI MergeContent
apache