Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test sysctl vm.max_map_count before failing init script #27236

Closed
biggreenogre opened this issue Nov 2, 2017 · 6 comments
Closed

Test sysctl vm.max_map_count before failing init script #27236

biggreenogre opened this issue Nov 2, 2017 · 6 comments
Labels
:Delivery/Packaging RPM and deb packaging, tar and zip archives, shell and batch scripts >enhancement Team:Delivery Meta label for Delivery team v6.4.1

Comments

@biggreenogre
Copy link

Elasticsearch version (bin/elasticsearch --version): <= current master

Plugins installed: n/a

JVM version (java -version): any

OS version (uname -a if on a Unix-like system): Linux xxxx 4.10.0-37-generic #41~16.04.1-Ubuntu SMP Fri Oct 6 22:42:59 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

Description of the problem including expected versus actual behavior:
elasticsearch daemon always fails to start when run inside a container.
Assuming value of vm.max_map_count >= MAX_MAP_COUNT, I expect the daemon to start when the init script is run.

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 distribution/deb/src/main/packaging/init.d/elasticsearch (and other OS scripts as applicable) as follows:

126c126,128
< 		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

As a sysadmin, it "feels wrong" to change a kernel parameter, potentially affecting other applications on the host, without first checking if the change is required. This patch 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 attempt to make the change and fail.

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.

More background info at voxpupuli/puppet-elasticsearch#887

regards,

Drew

Steps to reproduce:

  1. Install elasticsearch in a container
  2. Start with the init script
@jasontedor
Copy link
Member

I would accept a PR for this.

My only concern is for the portability of the test construct, in case it is too "BASH-centric".

This is fine, we require bash (although I would prefer $() instead of backticks, I plan to go through our scripts someday and replace the latter with the former).

Please ensure that the packaging tests pass too, perhaps expanding a test case if needed to cover the case when vm.max_map_count is already set appropriately. I can offer guidance running these if needed.

@jasontedor jasontedor added :Delivery/Packaging RPM and deb packaging, tar and zip archives, shell and batch scripts v6.1.0 labels Nov 3, 2017
@biggreenogre
Copy link
Author

Apologies for delay, vacation, work, etc.
Basic patches to deb and rpm init scripts is straight-forward but regarding tests, guidance would be most welcome.
Should I be looking in dev-tools/smoke_test_rc.py? Looks like it fires up a container but how can I set the sysctl var?

@lcawl lcawl added v6.2.0 and removed v6.1.0 labels Dec 12, 2017
@colings86 colings86 added v6.3.0 and removed v6.2.0 labels Jan 22, 2018
@jasontedor
Copy link
Member

Should I be looking in dev-tools/smoke_test_rc.py? Looks like it fires up a container but how can I set the sysctl var?

No, look at the packaging tests in qa/vagrant; you can create test that sets vm.max_map_count at the start of the test and then exercise the condition here.

@rjernst
Copy link
Member

rjernst commented Mar 12, 2018

@biggreenogre Are you still interested in contributing a PR for this?

@biggreenogre
Copy link
Author

biggreenogre commented Mar 23, 2018 via email

@danielmitterdorfer
Copy link
Member

This is already addressed by #31285 and #31512, hence closing.

dliappis pushed a commit that referenced this issue Feb 12, 2019
Currently init scripts fail when `/proc/sys/vm/max_map_count` is not present
with `-bash: [: too many arguments`.

Fix conditional logic to avoid trying to set the `max_map_count` sysctl if not
present.

Relates #27236
dliappis pushed a commit to dliappis/elasticsearch that referenced this issue Feb 12, 2019
…5933)

Currently init scripts fail when `/proc/sys/vm/max_map_count` is not present
with `-bash: [: too many arguments`.

Fix conditional logic to avoid trying to set the `max_map_count` sysctl if not
present.

Relates elastic#27236
dliappis pushed a commit to dliappis/elasticsearch that referenced this issue Feb 12, 2019
…5933)

Currently init scripts fail when `/proc/sys/vm/max_map_count` is not present
with `-bash: [: too many arguments`.

Fix conditional logic to avoid trying to set the `max_map_count` sysctl if not
present.

Relates elastic#27236
dliappis added a commit that referenced this issue Feb 13, 2019
Currently init scripts fail when `/proc/sys/vm/max_map_count` is not present
with `-bash: [: too many arguments`.

Fix conditional logic to avoid trying to set the `max_map_count` sysctl if not
present.

Backport of: #35933
Relates: #27236
dliappis added a commit that referenced this issue Feb 13, 2019
Currently init scripts fail when `/proc/sys/vm/max_map_count` is not present
with `-bash: [: too many arguments`.

Fix conditional logic to avoid trying to set the `max_map_count` sysctl if not
present.

Backport of: #35933
Relates: #27236
dliappis added a commit that referenced this issue Feb 13, 2019
Currently init scripts fail when `/proc/sys/vm/max_map_count` is not present
with `-bash: [: too many arguments`.

Fix conditional logic to avoid trying to set the `max_map_count` sysctl if not
present.

Backport of: #35933
Relates: #27236
@mark-vieira mark-vieira added the Team:Delivery Meta label for Delivery team label Nov 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Delivery/Packaging RPM and deb packaging, tar and zip archives, shell and batch scripts >enhancement Team:Delivery Meta label for Delivery team v6.4.1
Projects
None yet
Development

No branches or pull requests

8 participants