Blame SOURCES/nginx.init

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