freebsd-ports/net/rabbitmq/files/rabbitmq.in
Jimmy Olgeni f5f1d10932 net/rabbitmq: add full path to the daemon(8) call in rc script.
This allows the script to work in crontab, where /usr/sbin is not
in PATH.

Submitted by:	Dmitriy Simakov
MFH:		2017Q1
2017-01-26 09:41:06 +00:00

79 lines
1.9 KiB
Bash

#!/bin/sh
#
# $FreeBSD$
#
# 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
if [ -d ${RABBITMQ_LOG_BASE} ]; then
chown -R ${rabbitmq_user}:${rabbitmq_user} ${RABBITMQ_LOG_BASE}
fi
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}."
[ -f ${daemon_pidfile} ] && 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}
}
run_rc_command "$1"