Blame SOURCES/nginx.init

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