Blame SOURCES/nginx.init

36d786
#!/bin/sh
36d786
#
36d786
# nginx - this script starts and stops the nginx daemon
36d786
#
36d786
# chkconfig:   - 85 15
36d786
# description:  Nginx is an HTTP(S) server, HTTP(S) reverse \
36d786
#               proxy and IMAP/POP3 proxy server
36d786
# processname: nginx
36d786
# config:      /etc/nginx/nginx.conf
36d786
# config:      /etc/sysconfig/nginx
36d786
# pidfile:     /var/run/nginx.pid
36d786
36d786
# Source function library.
36d786
. /etc/rc.d/init.d/functions
36d786
36d786
# Source networking configuration.
36d786
. /etc/sysconfig/network
36d786
36d786
# Check that networking is up.
36d786
[ "$NETWORKING" = "no" ] && exit 0
36d786
36d786
nginx="$sbindir/nginx"
36d786
prog=$(basename $nginx)
36d786
36d786
sysconfig="$sysconfdir/sysconfig/$sclprefix$prog"
36d786
lockfile="$localstatedir/lock/subsys/nginx"
36d786
pidfile="$localstatedir/run/${prog}/${prog}.pid"
36d786
36d786
NGINX_CONF_FILE="$sysconfdir/nginx/nginx.conf"
36d786
36d786
[ -f $sysconfig ] && . $sysconfig
36d786
36d786
36d786
start() {
36d786
    [ -x $nginx ] || exit 5
36d786
    [ -f $NGINX_CONF_FILE ] || exit 6
36d786
    echo -n $"Starting $prog: "
36d786
    daemon $nginx -c $NGINX_CONF_FILE
36d786
    retval=$?
36d786
    echo
36d786
    [ $retval -eq 0 ] && touch $lockfile
36d786
    return $retval
36d786
}
36d786
36d786
stop() {
36d786
    echo -n $"Stopping $prog: "
36d786
    killproc -p $pidfile $prog
36d786
    retval=$?
36d786
    echo
36d786
    [ $retval -eq 0 ] && rm -f $lockfile
36d786
    return $retval
36d786
}
36d786
36d786
restart() {
36d786
    configtest_q || return 6
36d786
    stop
36d786
    start
36d786
}
36d786
36d786
reload() {
36d786
    configtest_q || return 6
36d786
    echo -n $"Reloading $prog: "
36d786
    killproc -p $pidfile $prog -HUP
36d786
    echo
36d786
}
36d786
36d786
configtest() {
36d786
    $nginx -t -c $NGINX_CONF_FILE
36d786
}
36d786
36d786
configtest_q() {
36d786
    $nginx -t -q -c $NGINX_CONF_FILE
36d786
}
36d786
36d786
rh_status() {
36d786
    status $prog
36d786
}
36d786
36d786
rh_status_q() {
36d786
    rh_status >/dev/null 2>&1
36d786
}
36d786
36d786
# Upgrade the binary with no downtime.
36d786
upgrade() {
36d786
    local oldbin_pidfile="${pidfile}.oldbin"
36d786
36d786
    configtest_q || return 6
36d786
    echo -n $"Upgrading $prog: "
36d786
    killproc -p $pidfile $prog -USR2
36d786
    retval=$?
36d786
    sleep 1
36d786
    if [[ -f ${oldbin_pidfile} && -f ${pidfile} ]];  then
36d786
        killproc -p $oldbin_pidfile $prog -QUIT
36d786
        success $"$prog online upgrade"
36d786
        echo 
36d786
        return 0
36d786
    else
36d786
        failure $"$prog online upgrade"
36d786
        echo
36d786
        return 1
36d786
    fi
36d786
}
36d786
36d786
# Tell nginx to reopen logs
36d786
reopen_logs() {
36d786
    configtest_q || return 6
36d786
    echo -n $"Reopening $prog logs: "
36d786
    killproc -p $pidfile $prog -USR1
36d786
    retval=$?
36d786
    echo
36d786
    return $retval
36d786
}
36d786
36d786
# We have to re-enable SCL environment, because /sbin/service
36d786
# clears almost all environment variables.
36d786
# Since X_SCLS is cleared as well, we lose information about other
36d786
# collections enabled.
36d786
source /opt/rh/$sclname/service-environment
36d786
source scl_source enable $$upperscl_SCLS_ENABLED
36d786
36d786
# we want start daemon only inside "scl enable" invocation
36d786
if ! scl_enabled $sclname; then
36d786
    echo "Collection $sclname has to be listed in /opt/rh/$sclname/service-environment"
36d786
    exit 1
36d786
fi
36d786
36d786
case "$1" in
36d786
    start)
36d786
        rh_status_q && exit 0
36d786
        $1
36d786
        ;;
36d786
    stop)
36d786
        rh_status_q || exit 0
36d786
        $1
36d786
        ;;
36d786
    restart|configtest|reopen_logs)
36d786
        $1
36d786
        ;;
36d786
    force-reload|upgrade) 
36d786
        rh_status_q || exit 7
36d786
        upgrade
36d786
        ;;
36d786
    reload)
36d786
        rh_status_q || exit 7
36d786
        $1
36d786
        ;;
36d786
    status|status_q)
36d786
        rh_$1
36d786
        ;;
36d786
    condrestart|try-restart)
36d786
        rh_status_q || exit 7
36d786
        restart
36d786
	    ;;
36d786
    *)
36d786
        echo $"Usage: $0 {start|stop|reload|configtest|status|force-reload|upgrade|restart|reopen_logs}"
36d786
        exit 2
36d786
esac