#!/bin/bash


# chkconfig: - 85 15

# description: The Nginx HTTP Server is an efficient and extensible  \

#              server implementing the current HTTP standards.



# Source function library.

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


nginx=/usr/local/nginx/sbin/nginx

prog=nginx

pidfile=/usr/local/nginx/logs/nginx.pid

lockfile=/var/lock/subsys/nginx

RETVAL=0



start() {

        echo -n $"Starting $prog: "

        daemon --pidfile=${pidfile} $nginx

        RETVAL=$?

        echo

        [ $RETVAL = 0 ] && touch ${lockfile}

        return $RETVAL

}



stop() {

        echo -n $"Stopping $prog: "

        killproc -p ${pidfile}  $nginx

        RETVAL=$?

        echo

        [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}

}


reload() {

    echo -n $"Reloading $prog: "

    if ! $nginx  -t ; then

        echo $"not reloading due to configuration syntax error"

        failure $"not reloading $nginx due to configuration syntax error"

    else

        # Force LSB behaviour from killproc

$nginx -s reload

        RETVAL=$?

        if [ $RETVAL -ne 0 ]; then

            failure $"nginx shutdown"

        fi

    fi

    echo

}





case "$1" in 

   "start" )

start

;;

   "stop" )

stop

;;

   "restart" )

stop

start

;;

   "status" )

status -p ${pidfile} $nginx

RETVAL=$?

;;


    "reload" )

reload

;;

     * )

echo "Usage: `basename $0` {start|stop|restart|status|reload}"

RETVAL=2

;;

esac


exit $RETVAL