#!/bin/sh
# v1.0
# nginx - Start, stop, or reconfigure nginx
#
# chkconfig: - 60 50
# description: nginx [engine x] is light http web/proxy server
#              that answers incoming ftp service requests.
# processname: nginx
# config: /etc/nginx/nginx.conf
# pidfile: /var/run/nginx.pid

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0

BINARY=/usr/sbin/nginx
CONF_FILE=/etc/nginx/nginx.conf
PID_FILE=/var/run/nginx.pid
[ -x $BINARY ] || exit 0

RETVAL=0
prog="nginx"

start() {
  # Start daemons.
  if [ -e $BINARY ] ; then

    echo -n $"Starting $prog: "
    $BINARY -c $CONF_FILE
    RETVAL=$?
    [ $RETVAL -eq 0 ] && {
    touch /var/lock/subsys/$prog
    success $"$prog"
  }
  echo
else
  RETVAL=1
fi
return $RETVAL
}

stop() {
  # Stop daemons.
  echo -n $"Shutting down $prog: "
  kill -s QUIT `cat $PID_FILE 2>/dev/null`
  RETVAL=$?
  echo
  [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog
  return $RETVAL
}

# See how we were called.
case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  reconfigure)
    if [ -f /var/lock/subsys/$prog ]; then
      kill -s HUP `cat $PID_FILE 2>/dev/null`
      RETVAL=$?
    fi
    ;;
  status)
    status $prog
    RETVAL=$?
    ;;
  *)
    echo $"Usage: $0 {start|stop|reconfigure|status}"
    exit 1
esac

exit $RETVAL