Blame rabbitmq-server.init

Hubert Plociniczak cc9fdf
#!/bin/sh
Hubert Plociniczak cc9fdf
#
Hubert Plociniczak cc9fdf
# rabbitmq-server RabbitMQ broker
Hubert Plociniczak cc9fdf
#
Hubert Plociniczak cc9fdf
# chkconfig: - 80 05
Hubert Plociniczak cc9fdf
# description: Enable AMQP service provided by RabbitMQ
Hubert Plociniczak cc9fdf
#
Hubert Plociniczak cc9fdf
Hubert Plociniczak cc9fdf
### BEGIN INIT INFO
Hubert Plociniczak cc9fdf
# Provides:          rabbitmq-server
Hubert Plociniczak cc9fdf
# Required-Start:    $remote_fs $network
Hubert Plociniczak cc9fdf
# Required-Stop:     $remote_fs $network
Hubert Plociniczak cc9fdf
# Description:       RabbitMQ broker
Hubert Plociniczak cc9fdf
# Short-Description: Enable AMQP service provided by RabbitMQ broker
Hubert Plociniczak cc9fdf
### END INIT INFO
Hubert Plociniczak cc9fdf
d817ac
# Source function library.
d817ac
. /etc/init.d/functions
d817ac
Hubert Plociniczak cc9fdf
PATH=/sbin:/usr/sbin:/bin:/usr/bin
Hubert Plociniczak cc9fdf
NAME=rabbitmq-server
f44ad9
DAEMON=/usr/sbin/${NAME}
f44ad9
CONTROL=/usr/sbin/rabbitmqctl
Hubert Plociniczak cc9fdf
DESC=rabbitmq-server
Hubert Plociniczak cc9fdf
USER=rabbitmq
Hubert Plociniczak cc9fdf
ROTATE_SUFFIX=
Hubert Plociniczak 597ff1
INIT_LOG_DIR=/var/log/rabbitmq
f44ad9
PID_FILE=/var/run/rabbitmq/pid
Hubert Plociniczak cc9fdf
d817ac
START_PROG="daemon"
Hubert Plociniczak cc9fdf
LOCK_FILE=/var/lock/subsys/$NAME
Hubert Plociniczak cc9fdf
Hubert Plociniczak cc9fdf
test -x $DAEMON || exit 0
f44ad9
test -x $CONTROL || exit 0
Hubert Plociniczak cc9fdf
Hubert Plociniczak cc9fdf
RETVAL=0
Hubert Plociniczak cc9fdf
set -e
Hubert Plociniczak cc9fdf
d817ac
[ -f /etc/default/${NAME} ] && . /etc/default/${NAME}
d817ac
362613
[ -f /etc/sysconfig/${NAME} ] && . /etc/sysconfig/${NAME}
362613
d817ac
ensure_pid_dir () {
d817ac
    PID_DIR=`dirname ${PID_FILE}`
d817ac
    if [ ! -d ${PID_DIR} ] ; then
d817ac
        mkdir -p ${PID_DIR}
d817ac
        chown -R ${USER}:${USER} ${PID_DIR}
d817ac
        chmod 755 ${PID_DIR}
d817ac
    fi
d817ac
}
d817ac
d817ac
remove_pid () {
d817ac
    rm -f ${PID_FILE}
d817ac
    rmdir `dirname ${PID_FILE}` || :
d817ac
}
d817ac
Hubert Plociniczak cc9fdf
start_rabbitmq () {
f44ad9
    status_rabbitmq quiet
f44ad9
    if [ $RETVAL = 0 ] ; then
f44ad9
        echo RabbitMQ is currently running
f44ad9
    else
Hubert Plociniczak cc9fdf
        RETVAL=0
362613
	# RABBIT_NOFILES_LIMIT from /etc/sysconfig/rabbitmq-server is not handled
362613
	# automatically
362613
	if [ "$RABBITMQ_NOFILES_LIMIT" ]; then
362613
		ulimit -n $RABBITMQ_NOFILES_LIMIT
362613
	fi
362613
d817ac
        ensure_pid_dir
f44ad9
        set +e
d817ac
        RABBITMQ_PID_FILE=$PID_FILE $START_PROG $DAEMON \
d817ac
            > "${INIT_LOG_DIR}/startup_log" \
d817ac
            2> "${INIT_LOG_DIR}/startup_err" \
d817ac
            0<&- &
f44ad9
        $CONTROL wait $PID_FILE >/dev/null 2>&1
f44ad9
        RETVAL=$?
f44ad9
        set -e
f44ad9
        case "$RETVAL" in
f44ad9
            0)
f44ad9
                echo SUCCESS
f44ad9
                if [ -n "$LOCK_FILE" ] ; then
f44ad9
                    touch $LOCK_FILE
f44ad9
                fi
f44ad9
                ;;
f44ad9
            *)
d817ac
                remove_pid
f44ad9
                echo FAILED - check ${INIT_LOG_DIR}/startup_\{log, _err\}
f44ad9
                RETVAL=1
f44ad9
                ;;
f44ad9
        esac
f44ad9
    fi
Hubert Plociniczak cc9fdf
}
Hubert Plociniczak cc9fdf
Hubert Plociniczak cc9fdf
stop_rabbitmq () {
Hubert Plociniczak cc9fdf
    status_rabbitmq quiet
Hubert Plociniczak cc9fdf
    if [ $RETVAL = 0 ] ; then
f44ad9
        set +e
d817ac
        $CONTROL stop ${PID_FILE} > ${INIT_LOG_DIR}/shutdown_log 2> ${INIT_LOG_DIR}/shutdown_err
Hubert Plociniczak cc9fdf
        RETVAL=$?
f44ad9
        set -e
Hubert Plociniczak 597ff1
        if [ $RETVAL = 0 ] ; then
d817ac
            remove_pid
f44ad9
            if [ -n "$LOCK_FILE" ] ; then
f44ad9
                rm -f $LOCK_FILE
f44ad9
            fi
Hubert Plociniczak cc9fdf
        else
Hubert Plociniczak 597ff1
            echo FAILED - check ${INIT_LOG_DIR}/shutdown_log, _err
Hubert Plociniczak cc9fdf
        fi
Hubert Plociniczak cc9fdf
    else
f44ad9
        echo RabbitMQ is not running
Hubert Plociniczak cc9fdf
        RETVAL=0
Hubert Plociniczak cc9fdf
    fi
Hubert Plociniczak cc9fdf
}
Hubert Plociniczak cc9fdf
Hubert Plociniczak cc9fdf
status_rabbitmq() {
Hubert Plociniczak cc9fdf
    set +e
Hubert Plociniczak cc9fdf
    if [ "$1" != "quiet" ] ; then
f44ad9
        $CONTROL status 2>&1
Hubert Plociniczak cc9fdf
    else
f44ad9
        $CONTROL status > /dev/null 2>&1
Hubert Plociniczak cc9fdf
    fi
Hubert Plociniczak cc9fdf
    if [ $? != 0 ] ; then
f44ad9
        RETVAL=3
Hubert Plociniczak cc9fdf
    fi
Hubert Plociniczak cc9fdf
    set -e
Hubert Plociniczak cc9fdf
}
Hubert Plociniczak cc9fdf
Hubert Plociniczak cc9fdf
rotate_logs_rabbitmq() {
Hubert Plociniczak cc9fdf
    set +e
f44ad9
    $CONTROL rotate_logs ${ROTATE_SUFFIX}
Hubert Plociniczak cc9fdf
    if [ $? != 0 ] ; then
Hubert Plociniczak cc9fdf
        RETVAL=1
Hubert Plociniczak cc9fdf
    fi
Hubert Plociniczak cc9fdf
    set -e
Hubert Plociniczak cc9fdf
}
Hubert Plociniczak cc9fdf
f44ad9
restart_running_rabbitmq () {
f44ad9
    status_rabbitmq quiet
f44ad9
    if [ $RETVAL = 0 ] ; then
f44ad9
        restart_rabbitmq
f44ad9
    else
f44ad9
        echo RabbitMQ is not runnning
f44ad9
        RETVAL=0
f44ad9
    fi
f44ad9
}
f44ad9
Hubert Plociniczak cc9fdf
restart_rabbitmq() {
f44ad9
    stop_rabbitmq
Hubert Plociniczak cc9fdf
    start_rabbitmq
Hubert Plociniczak cc9fdf
}
Hubert Plociniczak cc9fdf
Hubert Plociniczak cc9fdf
case "$1" in
Hubert Plociniczak cc9fdf
    start)
Hubert Plociniczak cc9fdf
        echo -n "Starting $DESC: "
Hubert Plociniczak cc9fdf
        start_rabbitmq
Hubert Plociniczak cc9fdf
        echo "$NAME."
Hubert Plociniczak cc9fdf
        ;;
Hubert Plociniczak cc9fdf
    stop)
Hubert Plociniczak cc9fdf
        echo -n "Stopping $DESC: "
Hubert Plociniczak cc9fdf
        stop_rabbitmq
Hubert Plociniczak cc9fdf
        echo "$NAME."
Hubert Plociniczak cc9fdf
        ;;
Hubert Plociniczak cc9fdf
    status)
Hubert Plociniczak cc9fdf
        status_rabbitmq
Hubert Plociniczak cc9fdf
        ;;
Hubert Plociniczak cc9fdf
    rotate-logs)
Hubert Plociniczak cc9fdf
        echo -n "Rotating log files for $DESC: "
Hubert Plociniczak cc9fdf
        rotate_logs_rabbitmq
Hubert Plociniczak cc9fdf
        ;;
f44ad9
    force-reload|reload|restart)
Hubert Plociniczak cc9fdf
        echo -n "Restarting $DESC: "
Hubert Plociniczak cc9fdf
        restart_rabbitmq
Hubert Plociniczak cc9fdf
        echo "$NAME."
Hubert Plociniczak cc9fdf
        ;;
f44ad9
    try-restart)
f44ad9
        echo -n "Restarting $DESC: "
f44ad9
        restart_running_rabbitmq
f44ad9
        echo "$NAME."
f44ad9
        ;;
Hubert Plociniczak cc9fdf
    *)
Hubert Plociniczak cc9fdf
        echo "Usage: $0 {start|stop|status|rotate-logs|restart|condrestart|try-restart|reload|force-reload}" >&2
Hubert Plociniczak 597ff1
        RETVAL=1
Hubert Plociniczak cc9fdf
        ;;
Hubert Plociniczak cc9fdf
esac
Hubert Plociniczak cc9fdf
Hubert Plociniczak cc9fdf
exit $RETVAL