Blame SOURCES/nginx.init

c4323e
#!/bin/sh
c4323e
#
c4323e
# nginx - this script starts and stops the nginx daemon
c4323e
#
c4323e
# chkconfig:   - 85 15
c4323e
# description:  Nginx is an HTTP(S) server, HTTP(S) reverse \
c4323e
#               proxy and IMAP/POP3 proxy server
c4323e
# processname: nginx
c4323e
# config:      /etc/nginx/nginx.conf
c4323e
# config:      /etc/sysconfig/nginx
c4323e
# pidfile:     /var/run/nginx.pid
c4323e
c4323e
# Source function library.
c4323e
. /etc/rc.d/init.d/functions
c4323e
c4323e
# Source networking configuration.
c4323e
. /etc/sysconfig/network
c4323e
c4323e
# Check that networking is up.
c4323e
[ "$NETWORKING" = "no" ] && exit 0
c4323e
c4323e
nginx="$sbindir/nginx"
c4323e
prog=$(basename $nginx)
c4323e
c4323e
sysconfig="$sysconfdir/sysconfig/$scl$prog"
c4323e
lockfile="$localstatedir/lock/subsys/nginx"
c4323e
pidfile="$localstatedir/run/${prog}/${prog}.pid"
c4323e
c4323e
NGINX_CONF_FILE="$sysconfdir/nginx/nginx.conf"
c4323e
c4323e
[ -f $sysconfig ] && . $sysconfig
c4323e
c4323e
c4323e
start() {
c4323e
    [ -x $nginx ] || exit 5
c4323e
    [ -f $NGINX_CONF_FILE ] || exit 6
c4323e
    echo -n $"Starting $prog: "
c4323e
    daemon $nginx -c $NGINX_CONF_FILE
c4323e
    retval=$?
c4323e
    echo
c4323e
    [ $retval -eq 0 ] && touch $lockfile
c4323e
    return $retval
c4323e
}
c4323e
c4323e
stop() {
c4323e
    echo -n $"Stopping $prog: "
c4323e
    killproc -p $pidfile $prog
c4323e
    retval=$?
c4323e
    echo
c4323e
    [ $retval -eq 0 ] && rm -f $lockfile
c4323e
    return $retval
c4323e
}
c4323e
c4323e
restart() {
c4323e
    configtest_q || return 6
c4323e
    stop
c4323e
    start
c4323e
}
c4323e
c4323e
reload() {
c4323e
    configtest_q || return 6
c4323e
    echo -n $"Reloading $prog: "
c4323e
    killproc -p $pidfile $prog -HUP
c4323e
    echo
c4323e
}
c4323e
c4323e
configtest() {
c4323e
    $nginx -t -c $NGINX_CONF_FILE
c4323e
}
c4323e
c4323e
configtest_q() {
c4323e
    $nginx -t -q -c $NGINX_CONF_FILE
c4323e
}
c4323e
c4323e
rh_status() {
c4323e
    status $prog
c4323e
}
c4323e
c4323e
rh_status_q() {
c4323e
    rh_status >/dev/null 2>&1
c4323e
}
c4323e
c4323e
# Upgrade the binary with no downtime.
c4323e
upgrade() {
c4323e
    local oldbin_pidfile="${pidfile}.oldbin"
c4323e
c4323e
    configtest_q || return 6
c4323e
    echo -n $"Upgrading $prog: "
c4323e
    killproc -p $pidfile $prog -USR2
c4323e
    retval=$?
c4323e
    sleep 1
c4323e
    if [[ -f ${oldbin_pidfile} && -f ${pidfile} ]];  then
c4323e
        killproc -p $oldbin_pidfile $prog -QUIT
c4323e
        success $"$prog online upgrade"
c4323e
        echo 
c4323e
        return 0
c4323e
    else
c4323e
        failure $"$prog online upgrade"
c4323e
        echo
c4323e
        return 1
c4323e
    fi
c4323e
}
c4323e
c4323e
# Tell nginx to reopen logs
c4323e
reopen_logs() {
c4323e
    configtest_q || return 6
c4323e
    echo -n $"Reopening $prog logs: "
c4323e
    killproc -p $pidfile $prog -USR1
c4323e
    retval=$?
c4323e
    echo
c4323e
    return $retval
c4323e
}
c4323e
c4323e
case "$1" in
c4323e
    start)
c4323e
        rh_status_q && exit 0
c4323e
        $1
c4323e
        ;;
c4323e
    stop)
c4323e
        rh_status_q || exit 0
c4323e
        $1
c4323e
        ;;
c4323e
    restart|configtest|reopen_logs)
c4323e
        $1
c4323e
        ;;
c4323e
    force-reload|upgrade) 
c4323e
        rh_status_q || exit 7
c4323e
        upgrade
c4323e
        ;;
c4323e
    reload)
c4323e
        rh_status_q || exit 7
c4323e
        $1
c4323e
        ;;
c4323e
    status|status_q)
c4323e
        rh_$1
c4323e
        ;;
c4323e
    condrestart|try-restart)
c4323e
        rh_status_q || exit 7
c4323e
        restart
c4323e
	    ;;
c4323e
    *)
c4323e
        echo $"Usage: $0 {start|stop|reload|configtest|status|force-reload|upgrade|restart|reopen_logs}"
c4323e
        exit 2
c4323e
esac