码迷,mamicode.com
首页 > 其他好文 > 详细

Nginx启动脚本

时间:2018-06-30 23:03:18      阅读:213      评论:0      收藏:0      [点我收藏+]

标签:wc -l   dev   TE   exit   conf   div   oca   ons   rest   

#!/bin/bash
#author Template
#Time 2018-06-30 22:07
# chkconfig  2345 40 98
# description nginx start/stop script

prefix=/usr/local/nginx

Nginx_Bin=${prefix}/sbin/nginx
Nginx_Pid=${prefix}/logs/nginx.pid
Nginx_Conf=${prefix}/conf/nginx.conf

. /etc/init.d/functions

function start(){
    
    if [ ! -f ${Nginx_Pid} ];then
    #if [ `netstat -tlunp  | grep nginx | wc -l` -eq 0 ];then
        ${Nginx_Bin}
        RETVAL=$?
        
        if [ ${RETVAL} -eq 0 ];then
            action "Nginx started" /bin/true
        else
            action "Nginx started" /bin/false
        fi
        return ${RETVAL}
    else
        echo "Nginx is running" 
        return 0
    fi
}

function stop(){

    if [ -f ${Nginx_Pid} ];then

        ${Nginx_Bin} -s stop
        RETVAL=$?
        if [ ${RETVAL} -eq 0 ];then
            action "Nginx stoped" /bin/true
            return ${RETVAL}
        else
            action  "Nginx stoped" /bin/false
            return ${RETVAL}
        fi
    else
        echo  "Nginx is not running" 
        return 1

    fi
}

function reload(){
    ${Nginx_Bin} -t -q -c ${Nginx_Conf} &> /dev/null
    RETVAL=$?
    if [ $RETVAL -eq 0 ];then
        ${Nginx_Bin} -s reload
        RETVAL=$?
        [ ${RETVAL} -eq 0 ] && action "Nginx reload" /bin/true || action "Nginx reload" /bin/false
    else
        action "Reload" /bin/false
           echo "Please check your configuration"
        return ${RETVAL}
    fi

}

case $1 in

    start)
        start
        RETVAL=$?
        ;;
    stop)
        stop
        RETVAL=$?
        ;;
    restart)
        stop
        sleep 1
        start
        RETVAL=$?
        ;;

    reload)
        reload
        RETVAL=$?
        ;;
    *)
        echo "Usage: $0 {start|stop|restart|reload}"
        exit 1
esac
exit $RETVAL

 

Nginx启动脚本

标签:wc -l   dev   TE   exit   conf   div   oca   ons   rest   

原文地址:https://www.cnblogs.com/Template/p/9248834.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!