From 470ac0ec959542fa82aee2bc09f36bf597b0d9c1 Mon Sep 17 00:00:00 2001 From: Dimitrios Liappis Date: Wed, 13 Feb 2019 09:56:47 +0200 Subject: [PATCH] Don't fail init script if `/proc/.../max_map_count` absent (#38789) 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 --- distribution/packages/src/deb/init.d/elasticsearch | 2 +- distribution/packages/src/rpm/init.d/elasticsearch | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/distribution/packages/src/deb/init.d/elasticsearch b/distribution/packages/src/deb/init.d/elasticsearch index 1e503fa0cfa..72eb635bba3 100755 --- a/distribution/packages/src/deb/init.d/elasticsearch +++ b/distribution/packages/src/deb/init.d/elasticsearch @@ -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 -a "$MAX_MAP_COUNT" -gt $(cat /proc/sys/vm/max_map_count) ]; then + if [ -n "$MAX_MAP_COUNT" -a -f /proc/sys/vm/max_map_count ] && [ "$MAX_MAP_COUNT" -gt $(cat /proc/sys/vm/max_map_count) ]; then sysctl -q -w vm.max_map_count=$MAX_MAP_COUNT fi diff --git a/distribution/packages/src/rpm/init.d/elasticsearch b/distribution/packages/src/rpm/init.d/elasticsearch index bdaf8fbec37..99d8ef45ef6 100644 --- a/distribution/packages/src/rpm/init.d/elasticsearch +++ b/distribution/packages/src/rpm/init.d/elasticsearch @@ -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 -a "$MAX_MAP_COUNT" -gt $(cat /proc/sys/vm/max_map_count) ]; then + if [ -n "$MAX_MAP_COUNT" -a -f /proc/sys/vm/max_map_count ] && [ "$MAX_MAP_COUNT" -gt $(cat /proc/sys/vm/max_map_count) ]; then sysctl -q -w vm.max_map_count=$MAX_MAP_COUNT fi