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 
相关推荐
℡終嚸♂6809 小时前
Apache Tomcat CVE-2025-55752 CTF Writeup
tomcat·apache·firefox
27669582929 小时前
某白山小程序限制PC端调试
python·小程序·apache·小程序逆向·某白山·限制pc调试
杰建云16711 小时前
商家小程序怎么做?
大数据·apache·小程序制作
小冷爱学习!1 天前
Apache Shiro 1.2.4 反序列化漏洞Shiro-550(CVE-2016-4437)
服务器·网络·python·安全·网络安全·apache
有趣灵魂1 天前
Java Spring Boot根据Word模板和动态数据生成Word文件
java·spring boot·word·apache
phltxy1 天前
分布式链路追踪实战:Apache SkyWalking 从入门到精通
分布式·apache·skywalking
大厂数码评测员3 天前
免费菜谱管理小程序怎么做才顺手:从情侣、个人、家庭三类场景拆需求和实现
服务器·小程序·apache
四方云3 天前
MySQL 迁移到 Apache Doris 生产实践:从评估到落地的完整指南
数据库·mysql·apache
小羊Yveesss3 天前
2026年商城小程序开发属于什么费用?
apache
大厂数码评测员3 天前
2026 年家庭菜谱记录工具怎么选:从功能边界和小程序代码实现看免费与付费差异
java·开发语言·apache