#!/bin/bash
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /etc/nginx/nginx.conf
# pidfile: /var/run/nginx.pid
# user: nginx

NGINX_BIN=/usr/sbin/nginx
test -x $NGINX_BIN || { echo "$NGINX_BIN not installed"; 
    if [ "$1" = "stop" ]; then exit 0;
    else exit 5; fi; }
NGINX_PID=/var/run/nginx.pid

. /etc/rc.status

rc_reset

case "$1" in
    start)
    echo -n "Starting nginx "
    /sbin/startproc -p $NGINX_PID $NGINX_BIN

    rc_status -v
    ;;
    stop)
    echo -n "Shutting down nginx "

    /sbin/killproc -p $NGINX_PID -TERM $NGINX_BIN

    rc_status -v
    ;;
    try-restart|condrestart)

    if test "$1" = "condrestart"; then
        echo "${attn} Use try-restart ${done}(LSB)${attn} rather than condrestart ${warn}(RH)${norm}"
    fi
    $0 status
    if test $? = 0; then
        $0 restart
    else
        rc_reset
    fi

    rc_status
    ;;
    restart)

    $0 stop
    $0 start

    rc_status
    ;;
    force-reload)

    echo -n "Reload service nginx "

    /sbin/killproc -p $NGINX_PID -HUP $NGINX_BIN
    rc_status -v

    ;;
    reload)

    echo -n "Reload service nginx "
    /sbin/killproc -p $NGINX_PID -HUP $NGINX_BIN
    rc_status -v
    
    ;;
    reopen)
        echo -n "Reopen the logfiles "
        /sbin/killproc -p $NGINX_PID -USR1 $NGINX_BIN
        rc_status -v
        ;;

    status)
    echo -n "Checking for service nginx "

    /sbin/checkproc -p $NGINX_PID $NGINX_BIN

    rc_status -v
    ;;
    probe)

    test /etc/nginx/nginx.conf -nt /var/run/nginx.pid && echo reload
    ;;
    *)
    echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload|probe}"
    exit 1
    ;;
esac
rc_exit
