#!/bin/bash

start() {

        if [ `netstat -tnlp | grep -w 80 | wc -l` -eq 1 ];then

                echo "Nginx is running......"

                exit 1

        else

                /application/nginx/sbin/nginx

                sleep 2

                echo "Nginx start successed......"

        fi

}

stop () {

        if [ `netstat -tnlp | grep -w 80 | wc -l` -ne 1 ];then

                echo "Nginx is not running......"

                exit 1

        else

                /application/nginx/sbin/nginx -s stop

                sleep 2

                echo "Nginx stop successed......"

        fi

}

reload () {

        if [ `netstat -tnlp | grep -w 80 | wc -l` -ne 1 ];then

                echo "Nginx is not running......"

                exit 1

        else

                /application/nginx/sbin/nginx -s reload

                sleep 2

                echo "Nginx reload successed......"

        fi

}

restart() {

        reload

}


case "$1" in

start)

        start

        ;;

stop)

        stop

        ;;

reload)

        reload

        ;;

restart)

        reload

        ;;

*)

        echo "USAGE:$0 {start|stop|reload|restart}"

        ;;

esac