Skip to content

Commit fbe1b1a

Browse files
committed
Refactor configuration handling a little (reuse the "config check" loop for SSL configuration checking)
1 parent e613dd7 commit fbe1b1a

File tree

1 file changed

+27
-29
lines changed

1 file changed

+27
-29
lines changed

docker-entrypoint.sh

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,33 @@ if [[ "$1" == rabbitmq* ]] && [ "$(id -u)" = '0' ]; then
99
exec gosu rabbitmq "$BASH_SOURCE" "$@"
1010
fi
1111

12-
ssl=
13-
if [ "$RABBITMQ_SSL_CERT_FILE" -a "$RABBITMQ_SSL_KEY_FILE" -a "$RABBITMQ_SSL_CA_FILE" ]; then
14-
ssl=1
15-
fi
12+
configs=(
13+
# https://www.rabbitmq.com/configure.html
14+
default_pass
15+
default_user
16+
default_vhost
17+
hipe_compile
18+
ssl_ca_file
19+
ssl_cert_file
20+
ssl_key_file
21+
)
22+
23+
haveConfig=
24+
haveSslConfig=
25+
for conf in "${configs[@]}"; do
26+
var="RABBITMQ_${conf^^}"
27+
val="${!var}"
28+
if [ "$val" ]; then
29+
haveConfig=1
30+
if [[ "$conf" == ssl_* ]]; then
31+
haveSslConfig=1
32+
fi
33+
fi
34+
done
1635

1736
# If long & short hostnames are not the same, use long hostnames
1837
if [ "$(hostname)" != "$(hostname -s)" ]; then
19-
export RABBITMQ_USE_LONGNAME=true
38+
: "${RABBITMQ_USE_LONGNAME:=true}"
2039
fi
2140

2241
if [ "$RABBITMQ_ERLANG_COOKIE" ]; then
@@ -34,35 +53,14 @@ if [ "$RABBITMQ_ERLANG_COOKIE" ]; then
3453
fi
3554

3655
if [ "$1" = 'rabbitmq-server' ]; then
37-
configs=(
38-
# https://www.rabbitmq.com/configure.html
39-
default_pass
40-
default_user
41-
default_vhost
42-
ssl_ca_file
43-
ssl_cert_file
44-
ssl_key_file
45-
hipe_compile
46-
)
47-
48-
haveConfig=
49-
for conf in "${configs[@]}"; do
50-
var="RABBITMQ_${conf^^}"
51-
val="${!var}"
52-
if [ "$val" ]; then
53-
haveConfig=1
54-
break
55-
fi
56-
done
57-
5856
if [ "$haveConfig" ]; then
5957
cat > /etc/rabbitmq/rabbitmq.config <<-'EOH'
6058
[
6159
{rabbit,
6260
[
6361
EOH
6462

65-
if [ "$ssl" ]; then
63+
if [ "$haveSslConfig" ]; then
6664
cat >> /etc/rabbitmq/rabbitmq.config <<-EOS
6765
{ tcp_listeners, [ ] },
6866
{ ssl_listeners, [ 5671 ] },
@@ -120,7 +118,7 @@ if [ "$1" = 'rabbitmq-server' ]; then
120118
{ listener, [
121119
EOF
122120

123-
if [ "$ssl" ]; then
121+
if [ "$haveSslConfig" ]; then
124122
cat >> /etc/rabbitmq/rabbitmq.config <<-EOS
125123
{ port, 15671 },
126124
{ ssl, true },
@@ -154,7 +152,7 @@ if [ "$1" = 'rabbitmq-server' ]; then
154152
fi
155153
fi
156154

157-
if [ "$ssl" ]; then
155+
if [ "$haveSslConfig" ]; then
158156
# Create combined cert
159157
cat "$RABBITMQ_SSL_CERT_FILE" "$RABBITMQ_SSL_KEY_FILE" > /tmp/combined.pem
160158
chmod 0400 /tmp/combined.pem

0 commit comments

Comments
 (0)