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
本站资源均来自互联网,仅供研究学习,禁止违法使用和商用,产生法律纠纷本站概不负责!如果侵犯了您的权益请与我们联系!
转载请注明出处: 免费源码网-免费的源码资源网站 » Shell篇之编写apache启动脚本
发表评论 取消回复