Blame SOURCES/nginx.init

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