Nginx 服务启动脚本

#!/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



作者头像
南宫俊逸创始人

做一个积极主动热情的人,为了想要完成的事情和实现的目标,拼命投入力量。

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

发表评论

期待各位的加入,让原创发挥活力,让阅读更有价值!登录注册
登录
用户名
密码
注册
用户名
密码
确认密码
邮箱
验证码
找回密码
用户名
邮箱
※ 重置链接将发送到邮箱