当前位置: > Linux教程 > 系统运维 >

Rabbitmq启动脚本

时间:2016-06-04 05:27来源:blog.linuxeye.com 作者:IT

记录一个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

如下图:

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


(责任编辑:IT)
------分隔线----------------------------
栏目列表
推荐内容