linux下nginx启动停止重启控制脚本
? ?這是控制nginx服務的腳本文件,包括控制nginx的啟動、重啟、停止、平滑重啟、對配置文件的額檢查。
[root@localhost ~]# cat nginx.sh?
#!/bin/env bash
# description:nginx server ? ###必須加描述
# nginx - this script is used to control nginx service
# processname nginx
# chkconfig: - 85 15
# edit by sun
# date 2014-07-03
# email address 1305627792@qq.com
nginx="/usr/local/nginx/sbin/nginx"
prog="nginx"
conf_file="/usr/local/nginx/conf/nginx.conf"
start() {
????if [ `pgrep $prog | wc -l` -eq 0 ];then
????????if [ -x $nginx ] && [ -f $conf_file ];then
????????????$nginx -c $conf_file
????????????ret=$?
????????????????if [ $ret -eq 0 ];then
????????????????????echo "$prog start ? ? ? successed"
????????????????else
????????????????????echo "$prog start ? ? ? failed"
????????????????fi
????????else
????????????echo "$prog config file not exist"
????????fi
????else
????????echo "$prog is already started ... "
fi
}
stop() {
????if [ `pgrep $prog | wc -l` -ne 0 ];then
????????killall -9 $prog
????????ret=$?
????????????if [ $ret -eq 0 ];then
????????????????echo "$prog stop ? ? ? successed"
????????????else
????????????????echo "$prog stop ? failed"
????????????fi
????else
????????echo "$prog is already stopped ..."
????fi
}
restart() {
????stop
????sleep 2
????start
}
reload() {
????if [ `pgrep $prog | wc -l` -ne 0 ];then
????????pid=`ps -ef | grep $prog | grep master | awk '{print $2}'`
????????????if [ -x $nginx ] && [ -f $conf_file ];then
????????????????kill -HUP $pid
????????????????ret=$?
????????????????????if [ $ret -eq 0 ];then
????????????????????????echo "$prog reload ?successed"
????????????????????else
????????????????????????echo "$prog reload ? ?failed"
????????????????????fi
????????????else
????????????????echo "$prog config file is not exist"
????????????fi
????else
????????echo "$prog is stopped, please start $prog first ..."
????fi
}
check() {
????if [ -x $nginx ] && [ -f $conf_file ];then
????????$nginx -t -c $conf_file
????????ret=$?
????????????if [ $ret -eq 0 ];then
????????????????echo "$prog check successed"
????????????else
????????????????echo "$prog check failed"
????????????fi
????else
????????echo "$prog program or config file not exit!"
????fi
}
case $1 in
????start)
????????????start?
????????????;;
????stop)
????????????stop
????????????;;
????restart)
????????????restart
????????????;;
????reload)
????????????reload
????????????;;
????check)
????????????check
????????????;;
????*)
????????echo "Usage: $0 {start|stop|restart|reload|check}"
esac
運行bash nginx.sh start等操作即可。
轉載于:https://blog.51cto.com/4593973/1433863
總結
以上是生活随笔為你收集整理的linux下nginx启动停止重启控制脚本的全部內容,希望文章能夠幫你解決所遇到的問題。
                            
                        - 上一篇: java synchronized wa
 - 下一篇: Python之道