Nginx 服务启动脚本

guiyun affiliate

#!/bin/bash

# chkconfig: 2345 10 90

# description: Nginx  Startup Script 

. /etc/rc.d/init.d/functions

function show_usage(){

        usage="Usage: `basename $0` [ start|stop|restart|reload ]"

        echo $usage

        exit

}

base_dir=/application/nginx/

[[ $# != 1 ]] && show_usage

 

nginx=${base_dir}sbin/nginx

case $1 in

start)

        [[ `netstat -ntlup|grep nginx|wc -l` > 0 ]] && failure && echo "Nginx is Running" && exit

        echo "Starting Nginx..."

        $nginx

        ([ $? -eq 0 ] && success && echo "Nginx starts successfully") || (failure && echo "Failed start nginx")

;;

stop)

        [[ `netstat -ntlup|grep nginx|wc -l` == 0 ]] && failure && echo "Nginx is NOT running" && exit

        echo "Stopping Nginx..."

        $nginx -s stop

        ([ $? -eq 0 ] && success && echo "Nginx stops successfully ") || (failure && echo "Failed stop nginx")

 

;;

restart)

        if [[ `netstat -ntlup|grep nginx|wc -l` == 0 ]]; then

                echo "Starting Nginx..."

                $nginx

                [ $? -eq 0 ] && success && echo "Nginx starts successfully"

        else

                echo "Stopping Nginx..."

                $nginx -s stop

                ([ $? -eq 0 ] && success && echo "Nginx stops successfully ") || (failure && echo "Failed stop nginx")

                echo "Starting Nginx..."

                $nginx

                ([ $? -eq 0 ] && success && echo "Nginx starts successfully ") || (failure && echo "Failed start nginx")

        fi

;;

reload)

        [[ `netstat -ntlup|grep nginx|wc -l` == 0 ]] && failure && echo "Nginx is NOT Running" && exit

        $nginx -s reload

        [ $? -eq 0 ] && success && echo "Nginx reloads successfully "

;;

*)

        show_usage

;;

esac



guiyun affiliate

作者头像
南宫俊逸创始人

君子好学,自强不息~

上一篇:Linux的150个命令和快捷键
下一篇:安装黑苹果系统(macOS Sierra 10.12.6)

相关推荐

4

发表评论