Skip to content

Commit fd27ced

Browse files
committed
Add "vm_memory_high_watermark" to the generated config, sourced from the value of the "memory.limit_in_bytes" cgroup restriction
1 parent 253abcc commit fd27ced

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

3.6/alpine/docker-entrypoint.sh

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ for conf in "${allConfigKeys[@]}"; do
9595
var="RABBITMQ_${conf^^}"
9696
val="${!var:-}"
9797
if [ "$val" ]; then
98+
if [ "${configDefaults[$conf]:-}" ] && [ "${configDefaults[$conf]}" = "$val" ]; then
99+
# if the value set is the same as the default, treat it as if it isn't set
100+
continue
101+
fi
98102
haveConfig=1
99103
case "$conf" in
100104
ssl_*) haveSslConfig=1 ;;
@@ -235,13 +239,26 @@ rabbit_env_config() {
235239
join $'\n' "${ret[@]}"
236240
}
237241

238-
if [ "$1" = 'rabbitmq-server' ] && [ "$haveConfig" ]; then
242+
shouldWriteConfig="$haveConfig"
243+
if [ ! -f /etc/rabbitmq/rabbitmq.config ]; then
244+
shouldWriteConfig=1
245+
fi
246+
247+
if [ "$1" = 'rabbitmq-server' ] && [ "$shouldWriteConfig" ]; then
239248
fullConfig=()
240249

241250
rabbitConfig=(
242251
"{ loopback_users, $(rabbit_array) }"
243252
)
244253

254+
# https://www.rabbitmq.com/memory.html#memsup-usage
255+
# "If the absolute limit is larger than the installed RAM or available virtual address space, the threshold is set to whichever limit is smaller."
256+
# specifically, if a memory limit isn't supplied to the container and "memory.limit_in_bytes" is thus an enormous constant, RabbitMQ will ignore it and use maximum available memory or address space instead
257+
if [ -r /sys/fs/cgroup/memory/memory.limit_in_bytes ]; then
258+
memLimit="$(< /sys/fs/cgroup/memory/memory.limit_in_bytes)"
259+
rabbitConfig+=( "{ vm_memory_high_watermark, { absolute, $memLimit } }" )
260+
fi
261+
245262
if [ "$haveSslConfig" ]; then
246263
IFS=$'\n'
247264
rabbitSslOptions=( $(rabbit_env_config 'ssl' "${sslConfigKeys[@]}") )

3.6/debian/docker-entrypoint.sh

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ for conf in "${allConfigKeys[@]}"; do
9595
var="RABBITMQ_${conf^^}"
9696
val="${!var:-}"
9797
if [ "$val" ]; then
98+
if [ "${configDefaults[$conf]:-}" ] && [ "${configDefaults[$conf]}" = "$val" ]; then
99+
# if the value set is the same as the default, treat it as if it isn't set
100+
continue
101+
fi
98102
haveConfig=1
99103
case "$conf" in
100104
ssl_*) haveSslConfig=1 ;;
@@ -235,13 +239,26 @@ rabbit_env_config() {
235239
join $'\n' "${ret[@]}"
236240
}
237241

238-
if [ "$1" = 'rabbitmq-server' ] && [ "$haveConfig" ]; then
242+
shouldWriteConfig="$haveConfig"
243+
if [ ! -f /etc/rabbitmq/rabbitmq.config ]; then
244+
shouldWriteConfig=1
245+
fi
246+
247+
if [ "$1" = 'rabbitmq-server' ] && [ "$shouldWriteConfig" ]; then
239248
fullConfig=()
240249

241250
rabbitConfig=(
242251
"{ loopback_users, $(rabbit_array) }"
243252
)
244253

254+
# https://www.rabbitmq.com/memory.html#memsup-usage
255+
# "If the absolute limit is larger than the installed RAM or available virtual address space, the threshold is set to whichever limit is smaller."
256+
# specifically, if a memory limit isn't supplied to the container and "memory.limit_in_bytes" is thus an enormous constant, RabbitMQ will ignore it and use maximum available memory or address space instead
257+
if [ -r /sys/fs/cgroup/memory/memory.limit_in_bytes ]; then
258+
memLimit="$(< /sys/fs/cgroup/memory/memory.limit_in_bytes)"
259+
rabbitConfig+=( "{ vm_memory_high_watermark, { absolute, $memLimit } }" )
260+
fi
261+
245262
if [ "$haveSslConfig" ]; then
246263
IFS=$'\n'
247264
rabbitSslOptions=( $(rabbit_env_config 'ssl' "${sslConfigKeys[@]}") )

0 commit comments

Comments
 (0)