Skip to content

Test sysctl vm.max_map_count before failing init script #887

@biggreenogre

Description

@biggreenogre
  • Module version: 5.4.3
  • Puppet version: ANY
  • OS and version: Ubuntu 16.04 Xenial

Bug description

elasticsearch daemon always fails to start when running inside a container.

The elasticsearch daemon requires that the value of /proc/sys/vm/max_map_count be equal to or greater than MAX_MAP_COUNT. The daemon init script attempts to set this value with sysctl.
Unfortunately, since this value cannot be set from inside a container, the init script always fails, even when the current value is perfectly good.
Issue was encountered in LXC containers, it also applies to LXD, Docker and other container environments.

Given that the smarter DevOps practitioner will set this value on the host PRIOR to starting the container, would it be reasonable to TEST the value before refusing to start the daemon?

I proposes a minor change to /files/etc/init.d/elasticsearch.Debian.erb (and other OS script templates as applicable) as follows:

--- a/files/etc/init.d/elasticsearch.Debian.erb
+++ b/files/etc/init.d/elasticsearch.Debian.erb
@@ -144,7 +144,9 @@ case "$1" in
        fi
 
        if [ -n "$MAX_MAP_COUNT" -a -f /proc/sys/vm/max_map_count ]; then
-               sysctl -q -w vm.max_map_count=$MAX_MAP_COUNT
+               if [ `sysctl -n vm.max_map_count` -lt $MAX_MAP_COUNT ];then
+                       sysctl -q -w vm.max_map_count=$MAX_MAP_COUNT
+               fi
        fi
 
        # Start Daemon

This adds a test of the current value of vm.max_map_count against MAX_MAP_COUNT. If the current value equals or exceeds the required value, no action is taken and the daemon will start. Only if the current value is insufficient, will the script the attempt to make the change and fail.

This potentially fixes an irritating issue, suffered by many, in a more elegant fashion than other methods proposed in the past.
My only concern is for the portability of the test construct, in case it is too "BASH-centric".

I will submit a pull request including patches for all the supported OS init scripts if this would be acceptable.

regards,

Drew

Some references:
elastic/elasticsearch#21899
#806
#745

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions