#!/bin/sh # # $FreeBSD: head/net/rabbitmq/files/rabbitmq.in 465357 2018-03-23 13:51:09Z olgeni $ # # PROVIDE: rabbitmq # REQUIRE: DAEMON # BEFORE: LOGIN # KEYWORD: shutdown # # Add the following line to /etc/rc.conf to enable RabbitMQ # # rabbitmq_enable="YES" . /etc/rc.subr name=rabbitmq rcvar=rabbitmq_enable load_rc_config $name # Set some defaults : ${rabbitmq_enable="NO"} : ${rabbitmq_user="rabbitmq"} rabbitmq_server="%%PREFIX%%/sbin/rabbitmq-server" rabbitmq_ctl="%%PREFIX%%/sbin/rabbitmqctl" rabbitmq_env_conf="%%PREFIX%%/etc/rabbitmq/rabbitmq-env.conf" pidfile="/var/run/${name}.pid" daemon_pidfile="/var/run/${name}-daemon.pid" start_cmd="${name}_start" stop_cmd="${name}_stop" rotate_logs_cmd="su -m ${rabbitmq_user} -c 'sh -c \"${rabbitmq_ctl} rotate_logs\"'" status_cmd="su -m ${rabbitmq_user} -c 'sh -c \"${rabbitmq_ctl} status\"'" extra_commands="rotate_logs status" : ${RABBITMQ_LOG_BASE:=/var/log/${name}} if [ -f ${rabbitmq_env_conf} ]; then . ${rabbitmq_env_conf} fi export RABBITMQ_HOME=/var/db/${name} # Prevent conflicts with amqp_client and rabbit_common applications that # may be installed in ERL_LIBS. unset ERL_LIBS rabbitmq_start() { echo "Starting ${name}." if [ -d ${RABBITMQ_HOME} ]; then chown -R ${rabbitmq_user}:${rabbitmq_user} ${RABBITMQ_HOME} fi mkdir -p ${RABBITMQ_LOG_BASE} chown -R ${rabbitmq_user}:${rabbitmq_user} ${RABBITMQ_LOG_BASE} if [ -f ${RABBITMQ_HOME}/.erlang.cookie ]; then chmod 600 ${RABBITMQ_HOME}/.erlang.cookie fi env HOME=${RABBITMQ_HOME} /usr/sbin/daemon -c -f -u ${rabbitmq_user} -p ${pidfile} -P ${daemon_pidfile} ${rabbitmq_server} debug "Running: rabbitmqctl wait ${pidfile}" ${rabbitmq_ctl} wait ${pidfile} >/dev/null 2>&1 } rabbitmq_stop() { echo "Stopping ${name}." if [ -f ${daemon_pidfile} ]; then read daemon_pid < ${daemon_pidfile} debug "Running: ${rabbitmq_ctl} stop ${pidfile}" su -m ${rabbitmq_user} -c "sh -c \"${rabbitmq_ctl} stop ${pidfile}\"" >/dev/null 2>&1 [ -n "${daemon_pid}" ] && wait_for_pids ${daemon_pid} else debug "Running: ${rabbitmq_ctl} stop" su -m ${rabbitmq_user} -c "sh -c \"${rabbitmq_ctl} stop\"" >/dev/null 2>&1 fi } run_rc_command "$1"