#! /bin/sh
#
# nginx        Startup script for the nginx HTTP Server
#
# chkconfig: - 85 15
# description: Nginx is a World Wide Web server.  It is used to serve \
#	       HTML files and CGI.
#
# Author:  Ryan Norbauer <ryan.norbauer@gmail.com>
# Modified:     Geoffrey Grosenbach http://topfunky.com
# Modified:     David Krmpotic http://davidhq.com
# Modified:	Kun Xi http://kunxi.org

set -e

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="nginx daemon"
DAEMON=/opt/nginx/sbin/nginx
CONFIGFILE=/opt/nginx/conf/nginx.conf
PIDFILE=/opt/nginx/logs/nginx.pid
SCRIPTNAME=/etc/init.d/nginx

# Gracefully exit if the package has been removed.
test -x $DAEMON || exit 0

start() {
	$DAEMON -c $CONFIGFILE || echo -en "\n already running"
}

stop() {
	kill -QUIT `cat $PIDFILE` || echo -en "\n not running"
}

restart() {
	kill -HUP `cat $PIDFILE` || echo -en "\n can't reload"
}

case "$1" in
  start)
    echo -n "Starting $DESC: "
    start
    echo "[OK]"
  ;;
  stop)
    echo -n "Stopping $DESC: "
    stop
    echo "[OK]"
  ;;
  restart|reload)
    echo -n "Restarting $DESC: "
    restart
    echo "[OK]"
  ;;
  *)
    echo "Usage: $SCRIPTNAME {start|stop|restart|reload}" >&2
    exit 3
  ;;
esac

exit $?
