RabbitMQ启动脚本

记录一个rabbitmq启动脚本,修改部分参数即可用。

  1. vi /etc/init.d/rabbitmq-server #脚本内容,见图下,需修改参数
  2. chmod +x /etc/init.d/rabbitmq-server
  3. chkconfig –add rabbitmq-server
  4. chkconfig rabbitmq-server on

如下图:

RabbitMQ启动脚本
  1. #!/bin/sh
  2. #
  3. # rabbitmq-server RabbitMQ broker
  4. #
  5. # chkconfig: – 80 05
  6. # description: Enable AMQP service provided by RabbitMQ
  7. #
  8. ### BEGIN INIT INFO
  9. # Provides:          rabbitmq-server
  10. # Required-Start:    $remote_fs $network
  11. # Required-Stop:     $remote_fs $network
  12. # Description:       RabbitMQ broker
  13. # Short-Description: Enable AMQP service provided by RabbitMQ broker
  14. ### END INIT INFO
  15. # Source function library.
  16. . /etc/init.d/functions
  17. PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/erlang/bin
  18. NAME=rabbitmq-server
  19. DAEMON=/usr/sbin/${NAME}
  20. CONTROL=/usr/sbin/rabbitmqctl
  21. DESC=rabbitmq-server
  22. USER=rabbitmq
  23. ROTATE_SUFFIX=
  24. INIT_LOG_DIR=/usr/local/rabbitmq/var/rabbitmq
  25. PID_FILE=/var/run/rabbitmq/pid
  26. START_PROG=”daemon”
  27. LOCK_FILE=/var/lock/subsys/$NAME
  28. test -x $DAEMON || exit 0
  29. test -x $CONTROL || exit 0
  30. RETVAL=0
  31. set -e
  32. [ -f /etc/default/${NAME} ] && . /etc/default/${NAME}
  33. [ -f /etc/sysconfig/${NAME} ] && . /etc/sysconfig/${NAME}
  34. ensure_pid_dir () {
  35.     PID_DIR=`dirname ${PID_FILE}`
  36.     if [ ! -d ${PID_DIR} ] ; then
  37.         mkdir -p ${PID_DIR}
  38.         chown -R ${USER}:${USER} ${PID_DIR}
  39.         chmod 755 ${PID_DIR}
  40.     fi
  41. }
  42. remove_pid () {
  43.     rm -f ${PID_FILE}
  44.     rmdir `dirname ${PID_FILE}` || :
  45. }
  46. start_rabbitmq () {
  47.     status_rabbitmq quiet
  48.     if [ $RETVAL = 0 ] ; then
  49.         echo RabbitMQ is currently running
  50.     else
  51.         RETVAL=0
  52.         # RABBIT_NOFILES_LIMIT from /etc/sysconfig/rabbitmq-server is not handled
  53.         # automatically
  54.         if [ “$RABBITMQ_NOFILES_LIMIT” ]; then
  55.                 ulimit -n $RABBITMQ_NOFILES_LIMIT
  56.         fi
  57.         ensure_pid_dir
  58.         set +e
  59.         RABBITMQ_PID_FILE=$PID_FILE $START_PROG $DAEMON \
  60.             > “${INIT_LOG_DIR}/startup_log” \
  61.             2> “${INIT_LOG_DIR}/startup_err” \
  62.             0<&- &
  63.         $CONTROL wait $PID_FILE >/dev/null 2>&1
  64.         RETVAL=$?
  65.         set -e
  66.         case “$RETVAL” in
  67.             0)
  68.                 echo SUCCESS
  69.                 if [ -n “$LOCK_FILE” ] ; then
  70.                     touch $LOCK_FILE
  71.                 fi
  72.                 ;;
  73.             *)
  74.                 remove_pid
  75.                 echo FAILED – check ${INIT_LOG_DIR}/startup_\{log, _err\}
  76.                 RETVAL=1
  77.                 ;;
  78.         esac
  79.     fi
  80. }
  81. stop_rabbitmq () {
  82.     status_rabbitmq quiet
  83.     if [ $RETVAL = 0 ] ; then
  84.         set +e
  85.         $CONTROL stop ${PID_FILE} > ${INIT_LOG_DIR}/shutdown_log 2> ${INIT_LOG_DIR}/shutdown_err
  86.         RETVAL=$?
  87.         set -e
  88.         if [ $RETVAL = 0 ] ; then
  89.             remove_pid
  90.             if [ -n “$LOCK_FILE” ] ; then
  91.                 rm -f $LOCK_FILE
  92.             fi
  93.         else
  94.             echo FAILED – check ${INIT_LOG_DIR}/shutdown_log, _err
  95.         fi
  96.     else
  97.         echo RabbitMQ is not running
  98.         RETVAL=0
  99.     fi
  100. }
  101. status_rabbitmq() {
  102.     set +e
  103.     if [ “$1” != “quiet” ] ; then
  104.         $CONTROL status 2>&1
  105.     else
  106.         $CONTROL status > /dev/null 2>&1
  107.     fi
  108.     if [ $? != 0 ] ; then
  109.         RETVAL=3
  110.     fi
  111.     set -e
  112. }
  113. rotate_logs_rabbitmq() {
  114.     set +e
  115.     $CONTROL rotate_logs ${ROTATE_SUFFIX}
  116.     if [ $? != 0 ] ; then
  117.         RETVAL=1
  118.     fi
  119.     set -e
  120. }
  121. restart_running_rabbitmq () {
  122.     status_rabbitmq quiet
  123.     if [ $RETVAL = 0 ] ; then
  124.         restart_rabbitmq
  125.     else
  126.         echo RabbitMQ is not runnning
  127.         RETVAL=0
  128.     fi
  129. }
  130. restart_rabbitmq() {
  131.     stop_rabbitmq
  132.     start_rabbitmq
  133. }
  134. case “$1” in
  135.     start)
  136.         echo -n “Starting $DESC: “
  137.         start_rabbitmq
  138.         echo “$NAME.”
  139.         ;;
  140.     stop)
  141.         echo -n “Stopping $DESC: “
  142.         stop_rabbitmq
  143.         echo “$NAME.”
  144.         ;;
  145.     status)
  146.         status_rabbitmq
  147.         ;;
  148.     rotate-logs)
  149.         echo -n “Rotating log files for $DESC: “
  150.         rotate_logs_rabbitmq
  151.         ;;
  152.     force-reload|reload|restart)
  153.         echo -n “Restarting $DESC: “
  154.         restart_rabbitmq
  155.         echo “$NAME.”
  156.         ;;
  157.     try-restart)
  158.         echo -n “Restarting $DESC: “
  159.         restart_running_rabbitmq
  160.         echo “$NAME.”
  161.         ;;
  162.     *)
  163.         echo “Usage: $0 {start|stop|status|rotate-logs|restart|condrestart|try-restart|reload|force-reload}” >&2
  164.         RETVAL=1
  165.         ;;
  166. esac
  167. exit $RETVAL

【AD】美国洛杉矶CN2 VPS/香港CN2 VPS/日本CN2 VPS推荐,延迟低、稳定性高、免费备份_搬瓦工vps

【AD】RackNerd 推出的 KVM VPS 特价优惠,在纽约、西雅图、圣何塞和阿什本每年仅需 12.88 美元!