#!/bin/sh
### the shell program is nginx start!!!
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/opt/csw/bin:/usr/local/nginx/sbin
NAME=nginx

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

PIDFILE=/usr/local/nginx/logs/$NAME.pid

SCRIPTNAME=/etc/init.d/$NAME

[ -x "$DAEMON" ] || exit 0

do_start()
{
      if [ -f $PIDFILE ]; then
         echo "Nginx program is runing!!!"
        exit 1
       else  
        $DAEMON 
        echo "Nginx program is the successful start!!! " 
       fi
        
}
 
do_stop()
{
        if  [ -f $PIDFILE ]; then 
          kill `cat $PIDFILE`
          rm -f $PIDFILE
          echo "Nginx program is stoping"
         else  
            echo "Nginx program is not runing!!!" 
        fi
}
 
do_reload ()
{
        if [ -f $PIDFILE ]; then
           kill -HUP `cat $PIDFILE`
           echo "Nginx program is reload"
        else
           echo "Nginx program is not runing!!!"
        fi 
}
case "$1" in
  start)
    do_start
    ;;
  stop)
    do_stop
    ;;
  restart)
    do_stop
    do_start
    ;;
  reload)
    do_reload
    ;;
  *)
    echo "Usage: $SCRIPTNAME {start|stop|restart|reload}" >&2
    ;;
esac