Skip to content

Commit 713ecee

Browse files
authored
Merge pull request #15855 from rabbitmq/conf-d-mk
Split make config into per-plugin files templated when plugins enabled
2 parents 8f0dbdd + 1a55ff1 commit 713ecee

1 file changed

Lines changed: 207 additions & 78 deletions

File tree

deps/rabbit_common/mk/rabbitmq-run.mk

Lines changed: 207 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -166,43 +166,113 @@ endif
166166
# Run a full RabbitMQ.
167167
# --------------------------------------------------------------------
168168

169-
define test_rabbitmq_config
170-
$(if $(RABBITMQ_NODE_PORT),listeners.tcp.default = $(RABBITMQ_NODE_PORT))
171-
loopback_users = none
172-
cluster_name = localhost
173-
$(if $(RABBITMQ_NODE_PORT),management.tcp.port = $(shell echo "$$(($(RABBITMQ_NODE_PORT) + 10000))"))
174-
$(if $(RABBITMQ_NODE_PORT),mqtt.listeners.tcp.default = $(shell echo "$$((1883 + $(RABBITMQ_NODE_PORT) - 5672))"))
175-
$(if $(RABBITMQ_NODE_PORT),web_mqtt.tcp.port = $(shell echo "$$((15675 + $(RABBITMQ_NODE_PORT) - 5672))"))
176-
$(if $(RABBITMQ_NODE_PORT),stomp.listeners.tcp.default = $(shell echo "$$((61613 + $(RABBITMQ_NODE_PORT) - 5672))"))
177-
$(if $(RABBITMQ_NODE_PORT),web_stomp.tcp.port = $(shell echo "$$((15674 + $(RABBITMQ_NODE_PORT) - 5672))"))
178-
$(if $(RABBITMQ_NODE_PORT),stream.listeners.tcp.default = $(shell echo "$$((5552 + $(RABBITMQ_NODE_PORT) - 5672))"))
179-
$(if $(RABBITMQ_NODE_PORT),prometheus.tcp.port = $(shell echo "$$((15692 + $(RABBITMQ_NODE_PORT) - 5672))"))
180-
raft.data_dir = $(RABBITMQ_QUORUM_DIR)
181-
stream.data_dir = $(RABBITMQ_STREAM_DIR)
169+
# Shell function that returns true when a plugin is enabled.
170+
# Handles the special value ALL (all plugins enabled) as well as an explicit
171+
# space- or comma-separated list of plugin names.
172+
define plugin_enabled_fn
173+
plugin_enabled() { \
174+
_enabled="$$1"; _plugin="$$2"; \
175+
case "$$_enabled" in \
176+
ALL) return 0 ;; \
177+
*"$$_plugin"*) return 0 ;; \
178+
esac; \
179+
return 1; \
180+
}
182181
endef
183182

184-
define test_rabbitmq_config_with_tls
185-
loopback_users = none
186-
listeners.ssl.default = 5671
187-
ssl_options.cacertfile = $(TEST_TLS_CERTS_DIR_in_config)/testca/cacert.pem
188-
ssl_options.certfile = $(TEST_TLS_CERTS_DIR_in_config)/server/cert.pem
189-
ssl_options.keyfile = $(TEST_TLS_CERTS_DIR_in_config)/server/key.pem
190-
ssl_options.verify = verify_peer
191-
ssl_options.fail_if_no_peer_cert = false
192-
ssl_options.honor_cipher_order = true
193-
management.listener.port = 15671
194-
management.listener.ssl = true
195-
management.listener.ssl_opts.cacertfile = $(TEST_TLS_CERTS_DIR_in_config)/testca/cacert.pem
196-
management.listener.ssl_opts.certfile = $(TEST_TLS_CERTS_DIR_in_config)/server/cert.pem
197-
management.listener.ssl_opts.keyfile = $(TEST_TLS_CERTS_DIR_in_config)/server/key.pem
198-
management.listener.ssl_opts.verify = verify_peer
199-
management.listener.ssl_opts.fail_if_no_peer_cert = false
200-
management.listener.ssl_opts.honor_cipher_order = true
201-
raft.data_dir = $(RABBITMQ_QUORUM_DIR)
202-
stream.data_dir = $(RABBITMQ_STREAM_DIR)
183+
# Write the conf.d configuration fragments for run-broker.
184+
# $(1) = conf.d directory
185+
# $(2) = node TCP port (may be empty)
186+
# $(3) = quorum data dir
187+
# $(4) = stream data dir
188+
# $(5) = RABBITMQ_ENABLED_PLUGINS value
189+
define write_config_files_broker
190+
$(plugin_enabled_fn); \
191+
enabled="$(5)"; \
192+
mkdir -p "$(1)"; \
193+
{ \
194+
$(if $(2),printf '%s\n' "listeners.tcp.default = $(2)"; )\
195+
printf '%s\n' \
196+
"loopback_users = none" \
197+
"cluster_name = localhost" \
198+
"raft.data_dir = $(3)"; \
199+
} > "$(1)/00-base.conf"; \
200+
if plugin_enabled "$$enabled" rabbitmq_management; then \
201+
$(if $(2),\
202+
printf '%s\n' "management.tcp.port = $$(($(2) + 10000))" > "$(1)/10-management.conf", \
203+
true); \
204+
fi; \
205+
if plugin_enabled "$$enabled" rabbitmq_mqtt; then \
206+
$(if $(2),\
207+
printf '%s\n' "mqtt.listeners.tcp.default = $$((1883 + $(2) - 5672))" > "$(1)/20-mqtt.conf", \
208+
true); \
209+
fi; \
210+
if plugin_enabled "$$enabled" rabbitmq_web_mqtt; then \
211+
$(if $(2),\
212+
printf '%s\n' "web_mqtt.tcp.port = $$((15675 + $(2) - 5672))" > "$(1)/30-web_mqtt.conf", \
213+
true); \
214+
fi; \
215+
if plugin_enabled "$$enabled" rabbitmq_stomp; then \
216+
$(if $(2),\
217+
printf '%s\n' "stomp.listeners.tcp.default = $$((61613 + $(2) - 5672))" > "$(1)/40-stomp.conf", \
218+
true); \
219+
fi; \
220+
if plugin_enabled "$$enabled" rabbitmq_web_stomp; then \
221+
$(if $(2),\
222+
printf '%s\n' "web_stomp.tcp.port = $$((15674 + $(2) - 5672))" > "$(1)/50-web_stomp.conf", \
223+
true); \
224+
fi; \
225+
if plugin_enabled "$$enabled" rabbitmq_stream; then \
226+
{ \
227+
$(if $(2),printf '%s\n' "stream.listeners.tcp.default = $$((5552 + $(2) - 5672))"; )\
228+
printf '%s\n' "stream.data_dir = $(4)"; \
229+
} > "$(1)/60-stream.conf"; \
230+
fi; \
231+
if plugin_enabled "$$enabled" rabbitmq_prometheus; then \
232+
$(if $(2),\
233+
printf '%s\n' "prometheus.tcp.port = $$((15692 + $(2) - 5672))" > "$(1)/70-prometheus.conf", \
234+
true); \
235+
fi
236+
endef
237+
238+
# Write the conf.d configuration fragments for run-tls-broker.
239+
# $(1) = conf.d directory
240+
# $(2) = quorum data dir
241+
# $(3) = stream data dir
242+
# $(4) = TLS certs directory
243+
# $(5) = RABBITMQ_ENABLED_PLUGINS value
244+
define write_config_files_tls_broker
245+
$(plugin_enabled_fn); \
246+
enabled="$(5)"; \
247+
mkdir -p "$(1)"; \
248+
printf '%s\n' \
249+
"loopback_users = none" \
250+
"listeners.ssl.default = 5671" \
251+
"ssl_options.cacertfile = $(4)/testca/cacert.pem" \
252+
"ssl_options.certfile = $(4)/server/cert.pem" \
253+
"ssl_options.keyfile = $(4)/server/key.pem" \
254+
"ssl_options.verify = verify_peer" \
255+
"ssl_options.fail_if_no_peer_cert = false" \
256+
"ssl_options.honor_cipher_order = true" \
257+
"raft.data_dir = $(2)" \
258+
"stream.data_dir = $(3)" \
259+
> "$(1)/00-base.conf"; \
260+
if plugin_enabled "$$enabled" rabbitmq_management; then \
261+
printf '%s\n' \
262+
"management.listener.port = 15671" \
263+
"management.listener.ssl = true" \
264+
"management.listener.ssl_opts.cacertfile = $(4)/testca/cacert.pem" \
265+
"management.listener.ssl_opts.certfile = $(4)/server/cert.pem" \
266+
"management.listener.ssl_opts.keyfile = $(4)/server/key.pem" \
267+
"management.listener.ssl_opts.verify = verify_peer" \
268+
"management.listener.ssl_opts.fail_if_no_peer_cert = false" \
269+
"management.listener.ssl_opts.honor_cipher_order = true" \
270+
> "$(1)/10-management.conf"; \
271+
fi
203272
endef
204273

205-
TEST_CONFIG_FILE ?= $(TEST_TMPDIR)/test.conf
274+
TEST_CONFIG_DIR ?= $(TEST_TMPDIR)/conf.d
275+
.PHONY: $(TEST_CONFIG_DIR)
206276
TEST_TLS_CERTS_DIR := $(TEST_TMPDIR)/tls-certs
207277
ifeq ($(origin TEST_TLS_CERTS_DIR_in_config),undefined)
208278
ifeq ($(PLATFORM),msys2)
@@ -213,10 +283,6 @@ endif
213283
export TEST_TLS_CERTS_DIR_in_config
214284
endif
215285

216-
.PHONY: $(TEST_CONFIG_FILE)
217-
$(TEST_CONFIG_FILE): node-tmpdir
218-
$(gen_verbose) printf "$(subst $(newline),\n,$(subst ",\",$(config)))" > $@
219-
220286
$(TEST_TLS_CERTS_DIR): node-tmpdir
221287
$(gen_verbose) $(MAKE) -C $(DEPS_DIR)/rabbitmq_ct_helpers/tools/tls-certs \
222288
DIR=$(TEST_TLS_CERTS_DIR) all
@@ -234,16 +300,22 @@ DIST_TARGET ?= test-dist
234300
endif
235301
endif
236302

237-
run-broker run-tls-broker: RABBITMQ_CONFIG_FILE := $(basename $(TEST_CONFIG_FILE))
238-
run-broker: config = $(test_rabbitmq_config)
239-
run-tls-broker: config = $(test_rabbitmq_config_with_tls)
240303
run-tls-broker: $(TEST_TLS_CERTS_DIR)
241304

242-
run-broker run-tls-broker: node-tmpdir $(DIST_TARGET) $(TEST_CONFIG_FILE)
305+
run-broker: node-tmpdir $(DIST_TARGET)
243306
$(maybe_enabled_plugins); \
307+
$(call write_config_files_broker,$(TEST_CONFIG_DIR),$(RABBITMQ_NODE_PORT),$(RABBITMQ_QUORUM_DIR),$(RABBITMQ_STREAM_DIR),$(RABBITMQ_ENABLED_PLUGINS)); \
244308
$(BASIC_SCRIPT_ENV_SETTINGS) \
245309
RABBITMQ_ALLOW_INPUT=true \
246-
RABBITMQ_CONFIG_FILE=$(RABBITMQ_CONFIG_FILE) \
310+
RABBITMQ_CONFIG_FILES=$(TEST_CONFIG_DIR) \
311+
$(RABBITMQ_SERVER)
312+
313+
run-tls-broker: node-tmpdir $(DIST_TARGET)
314+
$(maybe_enabled_plugins); \
315+
$(call write_config_files_tls_broker,$(TEST_CONFIG_DIR),$(RABBITMQ_QUORUM_DIR),$(RABBITMQ_STREAM_DIR),$(TEST_TLS_CERTS_DIR_in_config),$(RABBITMQ_ENABLED_PLUGINS)); \
316+
$(BASIC_SCRIPT_ENV_SETTINGS) \
317+
RABBITMQ_ALLOW_INPUT=true \
318+
RABBITMQ_CONFIG_FILES=$(TEST_CONFIG_DIR) \
247319
$(RABBITMQ_SERVER)
248320

249321
run-background-broker: node-tmpdir $(DIST_TARGET)
@@ -338,7 +410,9 @@ start-brokers start-cluster: $(DIST_TARGET)
338410
# permissions to read-only, while another node also can't find
339411
# the cookie so it tries to create it, but it can't write
340412
# to a read-only file. Best option - just create the cookie upfront
341-
@if test ! -f "$$HOME/.erlang.cookie"; then \
413+
@$(plugin_enabled_fn); \
414+
enabled="$(RABBITMQ_ENABLED_PLUGINS)"; \
415+
if test ! -f "$$HOME/.erlang.cookie"; then \
342416
openssl rand -hex 20 > "$$HOME/.erlang.cookie" && \
343417
chmod 400 "$$HOME/.erlang.cookie"; \
344418
fi; \
@@ -356,29 +430,55 @@ start-brokers start-cluster: $(DIST_TARGET)
356430
for n in $$(seq $(NODES)); do \
357431
nodename="rabbit-$$n@$(HOSTNAME)"; \
358432
nodedir="$(TEST_TMPDIR)/$$nodename"; \
359-
mkdir -p "$$nodedir"; \
433+
confd="$$nodedir/conf.d"; \
434+
mkdir -p "$$confd"; \
435+
port="$$((5672 + $$n - 1))"; \
360436
printf '%s\n' \
361437
"loopback_users = none" \
362438
"cluster_name = localhost" \
363-
"listeners.tcp.default = $$((5672 + $$n - 1))" \
364-
"management.tcp.port = $$((15672 + $$n - 1))" \
365-
"mqtt.listeners.tcp.default = $$((1883 + $$n - 1))" \
366-
"web_mqtt.tcp.port = $$((1893 + $$n - 1))" \
367-
"stomp.listeners.tcp.default = $$((61613 + $$n - 1))" \
368-
"web_stomp.tcp.port = $$((61623 + $$n - 1))" \
369-
"prometheus.tcp.port = $$((15692 + $$n - 1))" \
370-
"stream.listeners.tcp.default = $$((5552 + $$n - 1))" \
371-
> "$$nodedir/rabbitmq.conf"; \
439+
"listeners.tcp.default = $$port" \
440+
> "$$confd/00-base.conf"; \
441+
if plugin_enabled "$$enabled" rabbitmq_management; then \
442+
printf '%s\n' "management.tcp.port = $$((15672 + $$n - 1))" \
443+
> "$$confd/10-management.conf"; \
444+
fi; \
445+
if plugin_enabled "$$enabled" rabbitmq_mqtt; then \
446+
printf '%s\n' "mqtt.listeners.tcp.default = $$((1883 + $$n - 1))" \
447+
> "$$confd/20-mqtt.conf"; \
448+
fi; \
449+
if plugin_enabled "$$enabled" rabbitmq_web_mqtt; then \
450+
printf '%s\n' "web_mqtt.tcp.port = $$((1893 + $$n - 1))" \
451+
> "$$confd/30-web_mqtt.conf"; \
452+
fi; \
453+
if plugin_enabled "$$enabled" rabbitmq_stomp; then \
454+
printf '%s\n' "stomp.listeners.tcp.default = $$((61613 + $$n - 1))" \
455+
> "$$confd/40-stomp.conf"; \
456+
fi; \
457+
if plugin_enabled "$$enabled" rabbitmq_web_stomp; then \
458+
printf '%s\n' "web_stomp.tcp.port = $$((61623 + $$n - 1))" \
459+
> "$$confd/50-web_stomp.conf"; \
460+
fi; \
461+
if plugin_enabled "$$enabled" rabbitmq_stream; then \
462+
printf '%s\n' "stream.listeners.tcp.default = $$((5552 + $$n - 1))" \
463+
> "$$confd/60-stream.conf"; \
464+
fi; \
465+
if plugin_enabled "$$enabled" rabbitmq_prometheus; then \
466+
printf '%s\n' "prometheus.tcp.port = $$((15692 + $$n - 1))" \
467+
> "$$confd/70-prometheus.conf"; \
468+
fi; \
469+
server_start_args="$$cluster_nodes_arg"; \
470+
if plugin_enabled "$$enabled" rabbitmq_web_mqtt; then \
471+
server_start_args="-rabbitmq_web_mqtt_examples listener [{port,$$((1903 + $$n - 1))}] $$server_start_args"; \
472+
fi; \
473+
if plugin_enabled "$$enabled" rabbitmq_web_stomp; then \
474+
server_start_args="-rabbitmq_web_stomp_examples listener [{port,$$((61633 + $$n - 1))}] $$server_start_args"; \
475+
fi; \
372476
$(MAKE) start-background-broker \
373477
NOBUILD=1 \
374478
RABBITMQ_NODENAME="$$nodename" \
375-
RABBITMQ_NODE_PORT="$$((5672 + $$n - 1))" \
376-
RABBITMQ_CONFIG_FILE="$$nodedir/rabbitmq" \
377-
RABBITMQ_SERVER_START_ARGS=" \
378-
-rabbitmq_web_mqtt_examples listener [{port,$$((1903 + $$n - 1))}] \
379-
-rabbitmq_web_stomp_examples listener [{port,$$((61633 + $$n - 1))}] \
380-
$$cluster_nodes_arg \
381-
" & \
479+
RABBITMQ_NODE_PORT="$$port" \
480+
RABBITMQ_CONFIG_FILES="$$confd" \
481+
RABBITMQ_SERVER_START_ARGS="$$server_start_args" & \
382482
done; \
383483
wait
384484

@@ -394,7 +494,9 @@ NODES ?= 3
394494

395495
# Rolling restart similar to what the Kubernetes Operator does
396496
restart-cluster:
397-
@for n in $$(seq $(NODES) -1 1); do \
497+
@$(plugin_enabled_fn); \
498+
enabled="$(RABBITMQ_ENABLED_PLUGINS)"; \
499+
for n in $$(seq $(NODES) -1 1); do \
398500
nodename="rabbit-$$n@$(HOSTNAME)"; \
399501
$(RABBITMQ_UPGRADE) -n "$$nodename" await_online_quorum_plus_one -t 604800 && \
400502
$(RABBITMQ_UPGRADE) -n "$$nodename" drain; \
@@ -403,29 +505,56 @@ restart-cluster:
403505
echo "Sleeping for $(RESTART_DELAY) seconds..."; \
404506
sleep $(RESTART_DELAY); \
405507
nodedir="$(TEST_TMPDIR)/$$nodename"; \
406-
mkdir -p "$$nodedir"; \
508+
confd="$$nodedir/conf.d"; \
509+
mkdir -p "$$confd"; \
510+
port="$$((5672 + $$n - 1))"; \
407511
printf '%s\n' \
408512
"loopback_users = none" \
409513
"cluster_name = localhost" \
410-
"listeners.tcp.default = $$((5672 + $$n - 1))" \
411-
"management.tcp.port = $$((15672 + $$n - 1))" \
412-
"mqtt.listeners.tcp.default = $$((1883 + $$n - 1))" \
413-
"web_mqtt.tcp.port = $$((1893 + $$n - 1))" \
414-
"stomp.listeners.tcp.default = $$((61613 + $$n - 1))" \
415-
"web_stomp.tcp.port = $$((61623 + $$n - 1))" \
416-
"prometheus.tcp.port = $$((15692 + $$n - 1))" \
417-
"stream.listeners.tcp.default = $$((5552 + $$n - 1))" \
418-
> "$$nodedir/rabbitmq.conf"; \
514+
"listeners.tcp.default = $$port" \
515+
> "$$confd/00-base.conf"; \
516+
if plugin_enabled "$$enabled" rabbitmq_management; then \
517+
printf '%s\n' "management.tcp.port = $$((15672 + $$n - 1))" \
518+
> "$$confd/10-management.conf"; \
519+
fi; \
520+
if plugin_enabled "$$enabled" rabbitmq_mqtt; then \
521+
printf '%s\n' "mqtt.listeners.tcp.default = $$((1883 + $$n - 1))" \
522+
> "$$confd/20-mqtt.conf"; \
523+
fi; \
524+
if plugin_enabled "$$enabled" rabbitmq_web_mqtt; then \
525+
printf '%s\n' "web_mqtt.tcp.port = $$((1893 + $$n - 1))" \
526+
> "$$confd/30-web_mqtt.conf"; \
527+
fi; \
528+
if plugin_enabled "$$enabled" rabbitmq_stomp; then \
529+
printf '%s\n' "stomp.listeners.tcp.default = $$((61613 + $$n - 1))" \
530+
> "$$confd/40-stomp.conf"; \
531+
fi; \
532+
if plugin_enabled "$$enabled" rabbitmq_web_stomp; then \
533+
printf '%s\n' "web_stomp.tcp.port = $$((61623 + $$n - 1))" \
534+
> "$$confd/50-web_stomp.conf"; \
535+
fi; \
536+
if plugin_enabled "$$enabled" rabbitmq_stream; then \
537+
printf '%s\n' "stream.listeners.tcp.default = $$((5552 + $$n - 1))" \
538+
> "$$confd/60-stream.conf"; \
539+
fi; \
540+
if plugin_enabled "$$enabled" rabbitmq_prometheus; then \
541+
printf '%s\n' "prometheus.tcp.port = $$((15692 + $$n - 1))" \
542+
> "$$confd/70-prometheus.conf"; \
543+
fi; \
544+
server_start_args=""; \
545+
if plugin_enabled "$$enabled" rabbitmq_web_mqtt; then \
546+
server_start_args="-rabbitmq_web_mqtt_examples listener [{port,$$((1903 + $$n - 1))}] $$server_start_args"; \
547+
fi; \
548+
if plugin_enabled "$$enabled" rabbitmq_web_stomp; then \
549+
server_start_args="-rabbitmq_web_stomp_examples listener [{port,$$((61633 + $$n - 1))}] $$server_start_args"; \
550+
fi; \
419551
$(MAKE) start-background-broker \
420552
NOBUILD=1 \
421553
RABBITMQ_NODENAME="$$nodename" \
422-
RABBITMQ_NODE_PORT="$$((5672 + $$n - 1))" \
423-
RABBITMQ_CONFIG_FILE="$$nodedir/rabbitmq" \
424-
RABBITMQ_SERVER_START_ARGS=" \
425-
-rabbitmq_web_mqtt_examples listener [{port,$$((1903 + $$n - 1))}] \
426-
-rabbitmq_web_stomp_examples listener [{port,$$((61633 + $$n - 1))}] \
427-
"; \
428-
$(RABBITMQCTL) -n "$$nodename" await_online_nodes $(NODES) || exit 1; \
554+
RABBITMQ_NODE_PORT="$$port" \
555+
RABBITMQ_CONFIG_FILES="$$confd" \
556+
RABBITMQ_SERVER_START_ARGS="$$server_start_args"; \
557+
$(RABBITMQCTL) -n "$$nodename" await_online_nodes $(NODES) || exit 1; \
429558
done; \
430559
wait
431560

0 commit comments

Comments
 (0)