Skip to content

Commit 42991e6

Browse files
committed
Fix bug in setting up RABBITMQ_PID_FILE as well as printing multi-line warnings and errors
1 parent ef41ee3 commit 42991e6

File tree

2 files changed

+32
-22
lines changed

2 files changed

+32
-22
lines changed

scripts/rabbitmq-env

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,32 @@ fi
4747

4848
_rmq_env_now()
4949
{
50-
date '+%Y-%m-%d %X'
50+
date '+%Y-%m-%d %H:%M:%S'
51+
}
52+
53+
_rmq_env_print()
54+
{
55+
_rmq_env_tmp="$1"
56+
shift
57+
printf '%s %s %s\n' "$(_rmq_env_now)" "$_rmq_env_tmp" "$1" 1>&2
58+
shift
59+
_rmq_env_print_line=''
60+
for _rmq_env_print_line in "$@"
61+
do
62+
printf ' %s\n' "$_rmq_env_print_line" 1>&2
63+
done
64+
unset _rmq_env_print_line
65+
unset _rmq_env_tmp
5166
}
5267

5368
_rmq_env_perr()
5469
{
55-
echo "$(_rmq_env_now) [error] $*" 1>&2
70+
_rmq_env_print '[error] ' "$@"
5671
}
5772

5873
_rmq_env_pwarn()
5974
{
60-
echo "$(_rmq_env_now) [warning] $*" 1>&2
75+
_rmq_env_print '[warning]' "$@"
6176
}
6277

6378
rmq_realpath() {
@@ -238,12 +253,12 @@ rmq_normalize_path_var \
238253

239254
[ "x" = "x$RABBITMQ_PID_FILE" ] && RABBITMQ_PID_FILE="$PID_FILE"
240255

241-
if [ -n "$saved_RABBITMQ_PID_FILE" ] && [ -n "$RABBITMQ_PID_FILE" ] && \
256+
if [ -n "$saved_RABBITMQ_PID_FILE" ] && \
242257
[ "$saved_RABBITMQ_PID_FILE" != "$RABBITMQ_PID_FILE" ]
243258
then
244-
_rmq_env_pwarn "RABBITMQ_PID_FILE was already set by the init script to:\n" \
245-
" $saved_RABBITMQ_PID_FILE\n" \
246-
" The value set in rabbitmq-env.conf is ignored because it would break the init script."
259+
_rmq_env_pwarn 'RABBITMQ_PID_FILE was already set by the init script to:' \
260+
"$saved_RABBITMQ_PID_FILE" \
261+
'The value set in rabbitmq-env.conf is ignored because it would break the init script.'
247262

248263
RABBITMQ_PID_FILE="$saved_RABBITMQ_PID_FILE"
249264
fi

scripts/rabbitmq-server

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,10 @@ RABBITMQ_CONFIG_FILE_NOEX=$(get_noex ${RABBITMQ_CONFIG_FILE})
9393
if [ "${RABBITMQ_CONFIG_FILE_NOEX}" = "${RABBITMQ_CONFIG_FILE}" ]; then
9494
if [ -f "${RABBITMQ_CONFIG_FILE_NOEX}.config" ]; then
9595
if [ -f "${RABBITMQ_CONFIG_FILE_NOEX}.conf" ]; then
96-
# Both files exist. Print a warning
97-
_rmq_env_pwarn "Both old (.config) and new (.conf) format config files exist.\n" \
98-
" " \
99-
"Using the old format config file: ${RABBITMQ_CONFIG_FILE_NOEX}.config\n" \
100-
" " \
101-
"Please update your config files to the new format and remove the old file"
96+
# Both files exist. Print a warning.
97+
_rmq_env_pwarn 'Both old (.config) and new (.conf) format config files exist.' \
98+
"Using the old format config file: ${RABBITMQ_CONFIG_FILE_NOEX}.config" \
99+
'Please update your config files to the new format and remove the old file.'
102100
fi
103101
RABBITMQ_CONFIG_FILE="${RABBITMQ_CONFIG_FILE_NOEX}.config"
104102
elif [ -f "${RABBITMQ_CONFIG_FILE_NOEX}.conf" ]; then
@@ -127,25 +125,22 @@ elif [ "${RABBITMQ_CONFIG_FILE_NOEX}.conf" = "${RABBITMQ_CONFIG_FILE}" ]; then
127125
elif [ "x" != "x${RABBITMQ_CONFIG_FILE}" \
128126
-a "${RABBITMQ_CONFIG_FILE_NOEX}" != "${RABBITMQ_CONFIG_FILE}" ]; then
129127
# Config file has an extension, but it's neither .conf or .config
130-
_rmq_env_perr "Wrong extension for RABBITMQ_CONFIG_FILE: ${RABBITMQ_CONFIG_FILE}\n" \
131-
" " \
132-
"The extension should be either .conf or .config"
128+
_rmq_env_perr "Wrong extension for RABBITMQ_CONFIG_FILE: ${RABBITMQ_CONFIG_FILE}" \
129+
'The extension should be either .conf or .config'
133130
exit 64 # EX_USAGE
134131
fi
135132

136133
RABBITMQ_CONFIG_ARG_FILE_NOEX=$(get_noex ${RABBITMQ_CONFIG_ARG_FILE})
137134

138135
if [ "${RABBITMQ_CONFIG_ARG_FILE_NOEX}.config" != "${RABBITMQ_CONFIG_ARG_FILE}" ]; then
139136
if [ "${RABBITMQ_CONFIG_ARG_FILE}" = "${RABBITMQ_ADVANCED_CONFIG_FILE}" ]; then
140-
_rmq_env_perr "Wrong extension for RABBITMQ_ADVANCED_CONFIG_FILE: ${RABBITMQ_ADVANCED_CONFIG_FILE}\n" \
141-
" " \
142-
"The extension should be .config"
137+
_rmq_env_perr "Wrong extension for RABBITMQ_ADVANCED_CONFIG_FILE: ${RABBITMQ_ADVANCED_CONFIG_FILE}" \
138+
'The extension should be .config'
143139
exit 64 # EX_USAGE
144140
else
145141
# We should never got here, but still there should be some explanation
146-
_rmq_env_perr "Wrong extension for ${RABBITMQ_CONFIG_ARG_FILE}\n" \
147-
" " \
148-
"The extension should be .config"
142+
_rmq_env_perr "Wrong extension for ${RABBITMQ_CONFIG_ARG_FILE}"
143+
'The extension should be .config'
149144
exit 64 # EX_USAGE
150145
fi
151146
fi

0 commit comments

Comments
 (0)