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 
相关推荐
倔强的石头10612 小时前
工业平台选型指南:权限、审计与多租户治理——用 Apache IoTDB 把“数据可用”升级为“数据可控”
人工智能·apache·iotdb
SeaTunnel16 小时前
Apache SeaTunnel 2.3.13 版本前瞻:核心引擎变化和 AI ETL 趋势值得关注
数据仓库·人工智能·apache·etl·seatunnel·数据同步
Apache IoTDB2 天前
谷歌编程之夏 2026:Apache IoTDB 项目征集正式开启!
apache·iotdb
一个天蝎座 白勺 程序猿2 天前
Apache IoTDB(17):IoTDB数据保留时间管理从TTL设置到智能数据生命周期控制
数据库·apache·时序数据库·iotdb
DolphinScheduler社区2 天前
Apache DolphinScheduler 2 月社区动态:功能升级与优化齐飞
开源·apache·任务调度·开源社区·海豚调度·大数据工作流调度
jgyzl2 天前
2026.3.10 Apache POI的学习及思考
学习·apache
身如柳絮随风扬2 天前
Apache POI导出Word,PPT完整实现
spring boot·word·powerpoint·apache
xiaoliuliu123452 天前
CentOS 7 使用 apache-tomcat-7.0.27.tar.gz 详细步骤(解压、配置、启动、测试)
centos·tomcat·apache
吴声子夜歌2 天前
小程序——录音、音频播放控制和背景音乐
小程序·apache·音视频
james的分享16 天前
大数据领域核心 SQL 优化框架Apache Calcite介绍
大数据·sql·apache·calcite