Skip to content

Commit

Permalink
Do not run sysctl for vm.max_map_count when its already set to th…
Browse files Browse the repository at this point in the history
…e same or greater value.

Context: This fails in a docker container otherwise.

Signed-off-by: Ben Abrams <me@benabrams.it>
  • Loading branch information
majormoses committed Jun 13, 2018
1 parent 0bfd18c commit 9d82a67
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
2 changes: 1 addition & 1 deletion distribution/packages/src/deb/init.d/elasticsearch
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ case "$1" in
ulimit -l $MAX_LOCKED_MEMORY
fi

if [ -n "$MAX_MAP_COUNT" -a -f /proc/sys/vm/max_map_count ]; then
if [ -n "$MAX_MAP_COUNT" -a -f /proc/sys/vm/max_map_count -a "$MAX_MAP_COUNT" -ge $(cat /proc/sys/vm/max_map_count) ]; then
sysctl -q -w vm.max_map_count=$MAX_MAP_COUNT
fi

Expand Down
2 changes: 1 addition & 1 deletion distribution/packages/src/rpm/init.d/elasticsearch
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ start() {
if [ -n "$MAX_LOCKED_MEMORY" ]; then
ulimit -l $MAX_LOCKED_MEMORY
fi
if [ -n "$MAX_MAP_COUNT" -a -f /proc/sys/vm/max_map_count ]; then
if [ -n "$MAX_MAP_COUNT" -a -f /proc/sys/vm/max_map_count -a "$MAX_MAP_COUNT" -ge $(cat /proc/sys/vm/max_map_count) ]; then
sysctl -q -w vm.max_map_count=$MAX_MAP_COUNT
fi

Expand Down
28 changes: 28 additions & 0 deletions qa/vagrant/src/test/resources/packaging/tests/70_sysv_initd.bats
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,31 @@ setup() {
assert_file_exist /var/log/elasticsearch/gc.log.0.current
stop_elasticsearch_service
}

# Ensures that if $MAX_MAP_COUNT is less than the set value on the OS
# it will be updated
@test "[INIT.D] sysctl is run when the value set is too small" {
# intentionally a ridiculously low number
sysctl -q -w vm.max_map_count=100
start_elasticsearch_service
max_map_count=$(sysctl -n vm.max_map_count)
stop_elasticsearch_service

[ $max_map_count != 100 ]

}

# Ensures that if $MAX_MAP_COUNT is greater than the set vaule on the OS
# we do not attempt to update it this should cover equality as well as I think
# we can trust that equality operators work as intended.
@test "[INIT.D] sysctl is not run when it already has a larger or equal value set" {
# intentionally set to the default +1
sysctl -q -w vm.max_map_count=262145
start_elasticsearch_service
max_map_count=$(sysctl -n vm.max_map_count)
stop_elasticsearch_service

# default value +1
[ $max_map_count = 262145 ]

}

0 comments on commit 9d82a67

Please sign in to comment.