1 #!/bin/sh2 #3 # rabbitmq-server RabbitMQ broker4 #5 # chkconfig: - 80 056 # description: Enable AMQP service provided by RabbitMQ7 #8
9 ### BEGIN INIT INFO10 # Provides: rabbitmq-server11 # Required-Start: $remote_fs $network12 # Required-Stop: $remote_fs $network13 # Description: RabbitMQ broker14 # Short-Description: Enable AMQP service provided by RabbitMQ broker15 ### END INIT INFO16
17 # Source function library.18 . /etc/init.d/functions19 export HOME=/root20 PATH=/sbin:/usr/sbin:/bin:/usr/bin21 NAME=rabbitmq-server22 #DAEMON=/usr/sbin/${NAME}23 #CONTROL=/usr/sbin/rabbitmqctl24 DAEMON=/server/rabbitmq/sbin/${NAME}25 CONTROL=/server/rabbitmq/sbin/rabbitmqctl26 DESC=rabbitmq-server27 USER=root28 ROTATE_SUFFIX=29 INIT_LOG_DIR=/var/log/rabbitmq30 PID_FILE=/var/run/rabbitmq/pid31
32 START_PROG="daemon"33 LOCK_FILE=/var/lock/subsys/$NAME34
35 test -x $DAEMON || exit 036 test -x $CONTROL || exit 037
38 RETVAL=039 set -e40
41 [ -f /etc/default/${NAME} ] && . /etc/default/${NAME}42
43 ensure_pid_dir () {44 PID_DIR=`dirname ${PID_FILE}`45 if [ ! -d ${PID_DIR} ] ; then46 mkdir -p ${PID_DIR}47 chown -R ${USER}:${USER} ${PID_DIR}48 chmod 755 ${PID_DIR}49 fi50 }51
52 remove_pid () {53 rm -f ${PID_FILE}54 rmdir `dirname ${PID_FILE}` || :55 }56
57 start_rabbitmq () {58 status_rabbitmq quiet59 if [ $RETVAL = 0 ] ; then60 echo RabbitMQ is currently running61 else62 RETVAL=063 ensure_pid_dir64 set +e65 RABBITMQ_PID_FILE=$PID_FILE $START_PROG $DAEMON66 > "${INIT_LOG_DIR}/startup_log"67 2> "${INIT_LOG_DIR}/startup_err"68 0/dev/null 2>&1
70 RETVAL=$?71 set -e72 case "$RETVAL" in73 0)74 echo SUCCESS75 if [ -n "$LOCK_FILE" ] ; then76 touch $LOCK_FILE77 fi78 ;;79 *)80 remove_pid81 echo FAILED - check ${INIT_LOG_DIR}/startup_{log, _err}82 RETVAL=183 ;;84 esac85 fi86 }87
88 stop_rabbitmq () {89 status_rabbitmq quiet90 if [ $RETVAL = 0 ] ; then91 set +e92 $CONTROL stop ${PID_FILE} > ${INIT_LOG_DIR}/shutdown_log 2> ${INIT_LOG_DIR}/shutdown_err93 RETVAL=$?94 set -e95 if [ $RETVAL = 0 ] ; then96 remove_pid97 if [ -n "$LOCK_FILE" ] ; then98 rm -f $LOCK_FILE99 fi100 else101 echo FAILED - check ${INIT_LOG_DIR}/shutdown_log, _err102 fi103 else104 echo RabbitMQ is not running105 RETVAL=0106 fi107 }108
109 status_rabbitmq() {110 set +e111 if [ "$1" != "quiet" ] ; then112 $CONTROL status 2>&1
113 else114 $CONTROL status > /dev/null 2>&1
115 fi116 if [ $? != 0 ] ; then117 RETVAL=3118 fi119 set -e120 }121
122 rotate_logs_rabbitmq() {123 set +e124 $CONTROL rotate_logs ${ROTATE_SUFFIX}125 if [ $? != 0 ] ; then126 RETVAL=1127 fi128 set -e129 }130
131 restart_running_rabbitmq () {132 status_rabbitmq quiet133 if [ $RETVAL = 0 ] ; then134 restart_rabbitmq135 else136 echo RabbitMQ is not runnning137 RETVAL=0138 fi139 }140
141 restart_rabbitmq() {142 stop_rabbitmq143 start_rabbitmq144 }145
146 case "$1" in147 start)148 echo -n "Starting $DESC: "149 start_rabbitmq150 echo "$NAME."151 ;;152 stop)153 echo -n "Stopping $DESC: "154 stop_rabbitmq155 echo "$NAME."156 ;;157 status)158 status_rabbitmq159 ;;160 rotate-logs)161 echo -n "Rotating log files for $DESC: "162 rotate_logs_rabbitmq163 ;;164 force-reload|reload|restart)165 echo -n "Restarting $DESC: "166 restart_rabbitmq167 echo "$NAME."168 ;;169 try-restart)170 echo -n "Restarting $DESC: "171 restart_running_rabbitmq172 echo "$NAME."173 ;;174 *)175 echo "Usage: $0 {start|stop|status|rotate-logs|restart|condrestart|try-restart|reload|force-reload}" >&2
176 RETVAL=1177 ;;178 esac179
180 exit $RETVAL