启动脚本---》httpd,nginx
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了启动脚本---》httpd,nginx相关的知识,希望对你有一定的参考价值。
#vim httpd.sh
#!/bin/bash
#chkconfig: - 45 55
httpd=/usr/sbin/httpd
pid=/var/run/httpd/httpd.pid
start(){
if [ -f $pid ];then
echo 已经启动
exit
fi
echo "starting......"
$httpd
if [ $? -ne 0 ];then
echo "启动失败...."
else
echo "ok"
fi
}
stop(){
if [ ! -f $pid ];then
echo 已经关闭
exit
fi
echo "已经关闭....."
if [ -f $pid ];then
kill `cat $pid`
echo "关闭成功..."
else
echo "本来就关闭...."
fi
}
status(){
if [ -f $pid ];then
echo "staring...."
else
echo "已经关闭...."
fi
}
restart(){
if [ -f $pid ];then
echo "已经重启"
else
$httpd
fi
}
case $1 in
start)
start;;
stop)
stop;;
status)
status;;
restart)
restart;;
*)
echo "用法是$0 { start|stop|restart|status}"
esac
#vim nginx.sh
#!/bin/bash
#chkconfig: - 44 55
nginx=/usr/sbin/nginx
pid=/usr/local/nginx/logs/nginx.pid
start(){
if [ -f $pid ];then
echo "已经启动"
exit
fi
echo "starting......"
$nginx
if [ $? -ne 0 ];then
echo "启动失败...."
else
echo "启动成功"
fi
}
stop(){
if [ ! -f $pid ];then
echo "已经关闭..."
exit
fi
echo "已经关闭..."
if [ -f $pid ];then
kill `cat $pid`
echo "关闭成功..."
else
echo "本来就关闭....."
fi
}
status(){
if [ -f $pid ];then
echo "start....."
else
echo "已经关闭..."
fi
}
restart(){
if [ -f $pid ];then
echo "已经重启"
else
$nginx
echo "重启成功"
fi
}
case $1 in
start)
start;;
stop)
stop;;
status)
status;;
restart)
restart;;
*)
echo "用法是$0 {start|stop|restart|status}"
esac
#sh nginx.sh stop
本文出自 “12336621” 博客,请务必保留此出处http://12346621.blog.51cto.com/12336621/1914679
以上是关于启动脚本---》httpd,nginx的主要内容,如果未能解决你的问题,请参考以下文章