summaryrefslogtreecommitdiff
path: root/scripts/rabbitmq-env
diff options
context:
space:
mode:
authorMichael Klishin <michael@clojurewerkz.org>2015-12-24 00:18:14 +0300
committerMichael Klishin <michael@clojurewerkz.org>2015-12-24 00:18:14 +0300
commit0e2dccc019071b9e52b86fce32f752c0fa78d1d5 (patch)
tree046555115616197a76b54869ac6714575a6bd5b5 /scripts/rabbitmq-env
parentb2cf1238eea40f6a505a42d1bf10b75efcdff3bc (diff)
parent447e549860d6281b12bd9cbb2d11f04e741561aa (diff)
downloadrabbitmq-server-git-0e2dccc019071b9e52b86fce32f752c0fa78d1d5.tar.gz
Merge branch 'stable' into rabbitmq-server-485
Diffstat (limited to 'scripts/rabbitmq-env')
-rw-r--r--[-rwxr-xr-x]scripts/rabbitmq-env175
1 files changed, 144 insertions, 31 deletions
diff --git a/scripts/rabbitmq-env b/scripts/rabbitmq-env
index a5bf52ab6a..0014643260 100755..100644
--- a/scripts/rabbitmq-env
+++ b/scripts/rabbitmq-env
@@ -15,33 +15,52 @@
## Copyright (c) 2007-2015 Pivotal Software, Inc. All rights reserved.
##
-# We set +e here since since our test for "readlink -f" below needs to
-# be able to fail.
-set +e
-# Determine where this script is really located (if this script is
-# invoked from another script, this is the location of the caller)
-SCRIPT_PATH="$0"
-while [ -h "$SCRIPT_PATH" ] ; do
- # Determine if readlink -f is supported at all. TODO clean this up.
- FULL_PATH=`readlink -f $SCRIPT_PATH 2>/dev/null`
- if [ "$?" != "0" ]; then
- REL_PATH=`readlink $SCRIPT_PATH`
- if expr "$REL_PATH" : '/.*' > /dev/null; then
- SCRIPT_PATH="$REL_PATH"
- else
- SCRIPT_PATH="`dirname "$SCRIPT_PATH"`/$REL_PATH"
- fi
+if [ "$RABBITMQ_ENV_LOADED" = 1 ]; then
+ return 0;
+fi
+
+if [ -z "$RABBITMQ_SCRIPTS_DIR" ]; then
+ # We set +e here since since our test for "readlink -f" below needs to
+ # be able to fail.
+ set +e
+ # Determine where this script is really located (if this script is
+ # invoked from another script, this is the location of the caller)
+ SCRIPT_PATH="$0"
+ while [ -h "$SCRIPT_PATH" ] ; do
+ # Determine if readlink -f is supported at all. TODO clean this up.
+ FULL_PATH=`readlink -f $SCRIPT_PATH 2>/dev/null`
+ if [ "$?" != "0" ]; then
+ REL_PATH=`readlink $SCRIPT_PATH`
+ if expr "$REL_PATH" : '/.*' > /dev/null; then
+ SCRIPT_PATH="$REL_PATH"
+ else
+ SCRIPT_PATH="`dirname "$SCRIPT_PATH"`/$REL_PATH"
+ fi
+ else
+ SCRIPT_PATH=$FULL_PATH
+ fi
+ done
+ set -e
+
+ RABBITMQ_SCRIPTS_DIR=`dirname $SCRIPT_PATH`
+fi
+
+rmq_realpath() {
+ local path=$1
+
+ if [ -d "$path" ]; then
+ cd "$path" && pwd
+ elif [ -f "$path" ]; then
+ cd "$(dirname "$path")" && echo $(pwd)/$(basename "$path")
else
- SCRIPT_PATH=$FULL_PATH
+ echo "$path"
fi
-done
-set -e
+}
-SCRIPT_DIR=`dirname $SCRIPT_PATH`
-RABBITMQ_HOME="${SCRIPT_DIR}/.."
+RABBITMQ_HOME="$(rmq_realpath "${RABBITMQ_SCRIPTS_DIR}/..")"
## Set defaults
-. ${SCRIPT_DIR}/rabbitmq-defaults
+. ${RABBITMQ_SCRIPTS_DIR}/rabbitmq-defaults
## Common defaults
SERVER_ERL_ARGS="+P 1048576"
@@ -84,20 +103,36 @@ fi
##--- Set environment vars RABBITMQ_<var_name> to defaults if not set
-rmq_realpath() {
+rmq_normalize_path() {
local path=$1
- if [ -d "$path" ]; then
- cd "$path" && pwd
- elif [ -f "$path" ]; then
- cd "$(dirname "$path")" && echo $(pwd)/$(basename "$path")
- else
- echo "$path"
- fi
+ echo "$path" | sed -E -e 's,//+,/,g' -e 's,(.)/$,\1,'
+}
+
+rmq_normalize_path_var() {
+ local var warning
+
+ local prefix="WARNING:"
+
+ for var in "$@"; do
+ local path=$(eval "echo \"\$$var\"")
+ case "$path" in
+ */)
+ warning=1
+ echo "$prefix Removing trailing slash from $var" 1>&2
+ ;;
+ esac
+
+ eval "$var=$(rmq_normalize_path "$path")"
+
+ if [ "x$warning" = "x1" ]; then
+ prefix=" "
+ fi
+ done
}
rmq_check_if_shared_with_mnesia() {
- local var
+ local var warning
local mnesia_dir=$(rmq_realpath "${RABBITMQ_MNESIA_DIR}")
local prefix="WARNING:"
@@ -149,17 +184,29 @@ DEFAULT_NODE_PORT=5672
[ "x" = "x$RABBITMQ_MNESIA_DIR" ] && RABBITMQ_MNESIA_DIR=${MNESIA_DIR}
[ "x" = "x$RABBITMQ_MNESIA_DIR" ] && RABBITMQ_MNESIA_DIR=${RABBITMQ_MNESIA_BASE}/${RABBITMQ_NODENAME}
+rmq_normalize_path_var \
+ RABBITMQ_CONFIG_FILE \
+ RABBITMQ_LOG_BASE \
+ RABBITMQ_MNESIA_BASE \
+ RABBITMQ_MNESIA_DIR
+
[ "x" = "x$RABBITMQ_PID_FILE" ] && RABBITMQ_PID_FILE=${PID_FILE}
[ "x" = "x$RABBITMQ_PID_FILE" ] && RABBITMQ_PID_FILE=${RABBITMQ_MNESIA_DIR}.pid
+rmq_normalize_path_var RABBITMQ_PID_FILE
[ "x" = "x$RABBITMQ_BOOT_MODULE" ] && RABBITMQ_BOOT_MODULE=${BOOT_MODULE}
[ "x" = "x$RABBITMQ_PLUGINS_EXPAND_DIR" ] && RABBITMQ_PLUGINS_EXPAND_DIR=${PLUGINS_EXPAND_DIR}
[ "x" = "x$RABBITMQ_PLUGINS_EXPAND_DIR" ] && RABBITMQ_PLUGINS_EXPAND_DIR=${RABBITMQ_MNESIA_BASE}/${RABBITMQ_NODENAME}-plugins-expand
+rmq_normalize_path_var RABBITMQ_PLUGINS_EXPAND_DIR
+[ "x" != "x$RABBITMQ_ENABLED_PLUGINS_FILE" ] && RABBITMQ_ENABLED_PLUGINS_FILE_source=environment
[ "x" = "x$RABBITMQ_ENABLED_PLUGINS_FILE" ] && RABBITMQ_ENABLED_PLUGINS_FILE=${ENABLED_PLUGINS_FILE}
+rmq_normalize_path_var RABBITMQ_ENABLED_PLUGINS_FILE
+[ "x" != "x$RABBITMQ_PLUGINS_DIR" ] && RABBITMQ_PLUGINS_DIR_source=environment
[ "x" = "x$RABBITMQ_PLUGINS_DIR" ] && RABBITMQ_PLUGINS_DIR=${PLUGINS_DIR}
+rmq_normalize_path_var RABBITMQ_PLUGINS_DIR
## Log rotation
[ "x" = "x$RABBITMQ_LOGS" ] && RABBITMQ_LOGS=${LOGS}
@@ -167,6 +214,10 @@ DEFAULT_NODE_PORT=5672
[ "x" = "x$RABBITMQ_SASL_LOGS" ] && RABBITMQ_SASL_LOGS=${SASL_LOGS}
[ "x" = "x$RABBITMQ_SASL_LOGS" ] && RABBITMQ_SASL_LOGS="${RABBITMQ_LOG_BASE}/${RABBITMQ_NODENAME}-sasl.log"
+rmq_normalize_path_var \
+ RABBITMQ_LOGS \
+ RABBITMQ_SASL_LOGS
+
[ "x" = "x$RABBITMQ_CTL_ERL_ARGS" ] && RABBITMQ_CTL_ERL_ARGS=${CTL_ERL_ARGS}
# Check if files and directories non-related to Mnesia are configured
@@ -186,5 +237,67 @@ rmq_check_if_shared_with_mnesia \
##--- End of overridden <var_name> variables
+## Development-specific environment.
+if [ "${RABBITMQ_DEV_ENV}" ]; then
+ if [ "$(basename "$0")" = 'rabbitmq-plugins' -a \( \
+ "$RABBITMQ_PLUGINS_DIR_source" != 'environment' -o \
+ "$RABBITMQ_ENABLED_PLUGINS_FILE_source" != 'environment' \) ]; then
+ # We need to query the running node for the plugins directory
+ # and the "enabled plugins" file.
+ eval $( (${RABBITMQ_SCRIPTS_DIR}/rabbitmqctl eval \
+ '{ok, P} = application:get_env(rabbit, plugins_dir),
+ {ok, E} = application:get_env(rabbit, enabled_plugins_file),
+ io:format(
+ "plugins_dir=\"~s\"~n"
+ "enabled_plugins_file=\"~s\"~n", [P, E]).' \
+ 2>/dev/null | head -n 2) || :)
+ if [ "${plugins_dir}" -a \
+ "$RABBITMQ_PLUGINS_DIR_source" != 'environment' ]; then
+ RABBITMQ_PLUGINS_DIR="${plugins_dir}"
+ fi
+ if [ "${enabled_plugins_file}" -a \
+ "$RABBITMQ_ENABLED_PLUGINS_FILE_source" != 'environment' ]; then
+ RABBITMQ_ENABLED_PLUGINS_FILE="${enabled_plugins_file}"
+ fi
+ fi
+
+ if [ -d "${RABBITMQ_PLUGINS_DIR}" ]; then
+ # RabbitMQ was started with "make run-broker" from its own
+ # source tree. Take rabbit_common from the plugins directory.
+ ERL_LIBS="${RABBITMQ_PLUGINS_DIR}:${ERL_LIBS}"
+ else
+ # RabbitMQ runs from a testsuite or a plugin. The .ez files are
+ # not available under RabbitMQ source tree. We need to look at
+ # $DEPS_DIR and default locations.
+
+ if [ "${DEPS_DIR}" -a -d "${DEPS_DIR}/rabbit_common/ebin" ]; then
+ # $DEPS_DIR is set, and it contains rabbitmq-common, use
+ # this.
+ DEPS_DIR_norm="${DEPS_DIR}"
+ elif [ -f "${RABBITMQ_SCRIPTS_DIR}/../../../erlang.mk" -a \
+ -d "${RABBITMQ_SCRIPTS_DIR}/../../rabbit_common/ebin" ]; then
+ # Look at default locations: "deps" subdirectory inside a
+ # plugin or the Umbrella.
+ DEPS_DIR_norm="${RABBITMQ_SCRIPTS_DIR}/../.."
+ fi
+ DEPS_DIR_norm=$(rmq_realpath "${DEPS_DIR_norm}")
+
+ ERL_LIBS="${DEPS_DIR_norm}:${ERL_LIBS}"
+ fi
+else
+ if [ -d "${RABBITMQ_PLUGINS_DIR}" ]; then
+ # RabbitMQ was started from its install directory. Take
+ # rabbit_common from the plugins directory.
+ ERL_LIBS="${RABBITMQ_PLUGINS_DIR}:${ERL_LIBS}"
+ fi
+fi
+
+ERL_LIBS=${ERL_LIBS%:}
+if [ "$ERL_LIBS" ]; then
+ export ERL_LIBS
+fi
+
+RABBITMQ_ENV_LOADED=1
+
# Since we source this elsewhere, don't accidentally stop execution
true