From 694285800c7e1980bdae5f5b9ff721faeba2e06c Mon Sep 17 00:00:00 2001 From: Martijn Laarman Date: Fri, 25 Jan 2019 16:44:33 +0100 Subject: [PATCH] Exit batch files explictly using ERRORLEVEL (#29583) * Exit batch files explictly using ERRORLEVEL This makes sure the exit code is preserved when calling the batch files from different contexts other than DOS Fixes #29582 This also fixes specific error codes being masked by an explict exit /b 1 causing the useful exitcodes from ExitCodes to be lost. * fix line breaks for calling cli to match the bash scripts * indent size of bash files is 2, make sure editorconfig does the same for bat files * update indenting to match bash files * update elasticsearch-keystore.bat indenting * Update elasticsearch-node.bat to exit outside of endlocal (cherry picked from commit dfecb256cb566de2913cd00a040e289f80040428) --- .editorconfig | 3 +++ distribution/src/bin/elasticsearch-cli.bat | 2 ++ distribution/src/bin/elasticsearch-keystore.bat | 4 +++- distribution/src/bin/elasticsearch-plugin.bat | 5 ++++- distribution/src/bin/elasticsearch-service.bat | 2 ++ distribution/src/bin/elasticsearch-shard.bat | 4 +++- distribution/src/bin/elasticsearch-translog.bat | 4 +++- distribution/src/bin/elasticsearch.bat | 1 + .../plugin/security/src/main/bin/elasticsearch-certgen.bat | 4 +++- .../plugin/security/src/main/bin/elasticsearch-certutil.bat | 4 +++- .../plugin/security/src/main/bin/elasticsearch-migrate.bat | 4 +++- .../security/src/main/bin/elasticsearch-saml-metadata.bat | 4 +++- .../security/src/main/bin/elasticsearch-setup-passwords.bat | 4 +++- .../plugin/security/src/main/bin/elasticsearch-syskeygen.bat | 4 +++- x-pack/plugin/security/src/main/bin/elasticsearch-users.bat | 4 +++- x-pack/plugin/sql/src/main/bin/elasticsearch-sql-cli.bat | 1 + .../plugin/watcher/src/main/bin/elasticsearch-croneval.bat | 4 +++- 17 files changed, 46 insertions(+), 12 deletions(-) diff --git a/.editorconfig b/.editorconfig index 9d4bfbf55d3a1..c3a32bede3261 100644 --- a/.editorconfig +++ b/.editorconfig @@ -8,3 +8,6 @@ indent_style = space indent_size = 4 trim_trailing_whitespace = true insert_final_newline = true + +[*.bat] +indent_size = 2 diff --git a/distribution/src/bin/elasticsearch-cli.bat b/distribution/src/bin/elasticsearch-cli.bat index e17ade3b74af1..405f97ccc8dbf 100644 --- a/distribution/src/bin/elasticsearch-cli.bat +++ b/distribution/src/bin/elasticsearch-cli.bat @@ -21,3 +21,5 @@ if defined ES_ADDITIONAL_CLASSPATH_DIRECTORIES ( -cp "%ES_CLASSPATH%" ^ "%ES_MAIN_CLASS%" ^ %* + +exit /b %ERRORLEVEL% diff --git a/distribution/src/bin/elasticsearch-keystore.bat b/distribution/src/bin/elasticsearch-keystore.bat index b43182a273f6b..83372248fb61a 100644 --- a/distribution/src/bin/elasticsearch-keystore.bat +++ b/distribution/src/bin/elasticsearch-keystore.bat @@ -6,7 +6,9 @@ setlocal enableextensions set ES_MAIN_CLASS=org.elasticsearch.common.settings.KeyStoreCli call "%~dp0elasticsearch-cli.bat" ^ %%* ^ - || exit /b 1 + || goto exit endlocal endlocal +:exit +exit /b %ERRORLEVEL% diff --git a/distribution/src/bin/elasticsearch-plugin.bat b/distribution/src/bin/elasticsearch-plugin.bat index 7e71de790f03e..e447c7e847cf2 100644 --- a/distribution/src/bin/elasticsearch-plugin.bat +++ b/distribution/src/bin/elasticsearch-plugin.bat @@ -7,7 +7,10 @@ set ES_MAIN_CLASS=org.elasticsearch.plugins.PluginCli set ES_ADDITIONAL_CLASSPATH_DIRECTORIES=lib/tools/plugin-cli call "%~dp0elasticsearch-cli.bat" ^ %%* ^ - || exit /b 1 + || goto exit + endlocal endlocal +:exit +exit /b %ERRORLEVEL% diff --git a/distribution/src/bin/elasticsearch-service.bat b/distribution/src/bin/elasticsearch-service.bat index e03581ddfa6f9..0ddac239ecc03 100644 --- a/distribution/src/bin/elasticsearch-service.bat +++ b/distribution/src/bin/elasticsearch-service.bat @@ -252,3 +252,5 @@ goto:eof endlocal endlocal + +exit /b %ERRORLEVEL% diff --git a/distribution/src/bin/elasticsearch-shard.bat b/distribution/src/bin/elasticsearch-shard.bat index e861b197e873d..4db48f141fd6c 100644 --- a/distribution/src/bin/elasticsearch-shard.bat +++ b/distribution/src/bin/elasticsearch-shard.bat @@ -6,7 +6,9 @@ setlocal enableextensions set ES_MAIN_CLASS=org.elasticsearch.index.shard.ShardToolCli call "%~dp0elasticsearch-cli.bat" ^ %%* ^ - || exit /b 1 + || goto exit endlocal endlocal +:exit +exit /b %ERRORLEVEL% diff --git a/distribution/src/bin/elasticsearch-translog.bat b/distribution/src/bin/elasticsearch-translog.bat index 6a2e3046205fe..2a28366ddc6b8 100644 --- a/distribution/src/bin/elasticsearch-translog.bat +++ b/distribution/src/bin/elasticsearch-translog.bat @@ -6,7 +6,9 @@ setlocal enableextensions set ES_MAIN_CLASS=org.elasticsearch.index.translog.TranslogToolCli call "%~dp0elasticsearch-cli.bat" ^ %%* ^ - || exit /b 1 + || goto exit endlocal endlocal +:exit +exit /b %ERRORLEVEL% diff --git a/distribution/src/bin/elasticsearch.bat b/distribution/src/bin/elasticsearch.bat index 6e268c9b13321..9b67fa2e0ffa6 100644 --- a/distribution/src/bin/elasticsearch.bat +++ b/distribution/src/bin/elasticsearch.bat @@ -55,3 +55,4 @@ cd /d "%ES_HOME%" endlocal endlocal +exit /b %ERRORLEVEL% diff --git a/x-pack/plugin/security/src/main/bin/elasticsearch-certgen.bat b/x-pack/plugin/security/src/main/bin/elasticsearch-certgen.bat index bb303f740e5c3..d268ea04290dd 100644 --- a/x-pack/plugin/security/src/main/bin/elasticsearch-certgen.bat +++ b/x-pack/plugin/security/src/main/bin/elasticsearch-certgen.bat @@ -12,7 +12,9 @@ set ES_ADDITIONAL_SOURCES=x-pack-env;x-pack-security-env set ES_ADDITIONAL_CLASSPATH_DIRECTORIES=lib/tools/security-cli call "%~dp0elasticsearch-cli.bat" ^ %%* ^ - || exit /b 1 + || goto exit endlocal endlocal +:exit +exit /b %ERRORLEVEL% diff --git a/x-pack/plugin/security/src/main/bin/elasticsearch-certutil.bat b/x-pack/plugin/security/src/main/bin/elasticsearch-certutil.bat index 34f595824f82d..40dc4f5c29b4f 100644 --- a/x-pack/plugin/security/src/main/bin/elasticsearch-certutil.bat +++ b/x-pack/plugin/security/src/main/bin/elasticsearch-certutil.bat @@ -12,7 +12,9 @@ set ES_ADDITIONAL_SOURCES=x-pack-env;x-pack-security-env set ES_ADDITIONAL_CLASSPATH_DIRECTORIES=lib/tools/security-cli call "%~dp0elasticsearch-cli.bat" ^ %%* ^ - || exit /b 1 + || goto exit endlocal endlocal +:exit +exit /b %ERRORLEVEL% diff --git a/x-pack/plugin/security/src/main/bin/elasticsearch-migrate.bat b/x-pack/plugin/security/src/main/bin/elasticsearch-migrate.bat index 4b8e4f926d797..a50bc1a384ed0 100644 --- a/x-pack/plugin/security/src/main/bin/elasticsearch-migrate.bat +++ b/x-pack/plugin/security/src/main/bin/elasticsearch-migrate.bat @@ -11,7 +11,9 @@ set ES_MAIN_CLASS=org.elasticsearch.xpack.security.authc.esnative.ESNativeRealmM set ES_ADDITIONAL_SOURCES=x-pack-env;x-pack-security-env call "%~dp0elasticsearch-cli.bat" ^ %%* ^ - || exit /b 1 + || goto exit endlocal endlocal +:exit +exit /b %ERRORLEVEL% diff --git a/x-pack/plugin/security/src/main/bin/elasticsearch-saml-metadata.bat b/x-pack/plugin/security/src/main/bin/elasticsearch-saml-metadata.bat index 64a272dfbb5a6..f39aedaff02e0 100644 --- a/x-pack/plugin/security/src/main/bin/elasticsearch-saml-metadata.bat +++ b/x-pack/plugin/security/src/main/bin/elasticsearch-saml-metadata.bat @@ -11,7 +11,9 @@ set ES_MAIN_CLASS=org.elasticsearch.xpack.security.authc.saml.SamlMetadataComman set ES_ADDITIONAL_SOURCES=x-pack-env;x-pack-security-env call "%~dp0elasticsearch-cli.bat" ^ %%* ^ - || exit /b 1 + || goto exit endlocal endlocal +:exit +exit /b %ERRORLEVEL% diff --git a/x-pack/plugin/security/src/main/bin/elasticsearch-setup-passwords.bat b/x-pack/plugin/security/src/main/bin/elasticsearch-setup-passwords.bat index 3c956ca47ba26..b650fcf84830f 100644 --- a/x-pack/plugin/security/src/main/bin/elasticsearch-setup-passwords.bat +++ b/x-pack/plugin/security/src/main/bin/elasticsearch-setup-passwords.bat @@ -11,7 +11,9 @@ set ES_MAIN_CLASS=org.elasticsearch.xpack.security.authc.esnative.tool.SetupPass set ES_ADDITIONAL_SOURCES=x-pack-env;x-pack-security-env call "%~dp0elasticsearch-cli.bat" ^ %%* ^ - || exit /b 1 + || goto exit endlocal endlocal +:exit +exit /b %ERRORLEVEL% diff --git a/x-pack/plugin/security/src/main/bin/elasticsearch-syskeygen.bat b/x-pack/plugin/security/src/main/bin/elasticsearch-syskeygen.bat index 11414872d073b..31fc871a5f7d0 100644 --- a/x-pack/plugin/security/src/main/bin/elasticsearch-syskeygen.bat +++ b/x-pack/plugin/security/src/main/bin/elasticsearch-syskeygen.bat @@ -11,7 +11,9 @@ set ES_MAIN_CLASS=org.elasticsearch.xpack.security.crypto.tool.SystemKeyTool set ES_ADDITIONAL_SOURCES=x-pack-env;x-pack-security-env call "%~dp0elasticsearch-cli.bat" ^ %%* ^ - || exit /b 1 + || goto exit endlocal endlocal +:exit +exit /b %ERRORLEVEL% diff --git a/x-pack/plugin/security/src/main/bin/elasticsearch-users.bat b/x-pack/plugin/security/src/main/bin/elasticsearch-users.bat index 9b35895ed86c1..b2600adfad282 100644 --- a/x-pack/plugin/security/src/main/bin/elasticsearch-users.bat +++ b/x-pack/plugin/security/src/main/bin/elasticsearch-users.bat @@ -11,7 +11,9 @@ set ES_MAIN_CLASS=org.elasticsearch.xpack.security.authc.file.tool.UsersTool set ES_ADDITIONAL_SOURCES=x-pack-env;x-pack-security-env call "%~dp0elasticsearch-cli.bat" ^ %%* ^ - || exit /b 1 + || goto exit endlocal endlocal +:exit +exit /b %ERRORLEVEL% diff --git a/x-pack/plugin/sql/src/main/bin/elasticsearch-sql-cli.bat b/x-pack/plugin/sql/src/main/bin/elasticsearch-sql-cli.bat index cf159f0322363..48daf97b515ab 100644 --- a/x-pack/plugin/sql/src/main/bin/elasticsearch-sql-cli.bat +++ b/x-pack/plugin/sql/src/main/bin/elasticsearch-sql-cli.bat @@ -22,3 +22,4 @@ set CLI_JAR=%ES_HOME%/bin/* endlocal endlocal +exit /b %ERRORLEVEL% diff --git a/x-pack/plugin/watcher/src/main/bin/elasticsearch-croneval.bat b/x-pack/plugin/watcher/src/main/bin/elasticsearch-croneval.bat index 2b4a33c9f9e75..571c19056bb96 100644 --- a/x-pack/plugin/watcher/src/main/bin/elasticsearch-croneval.bat +++ b/x-pack/plugin/watcher/src/main/bin/elasticsearch-croneval.bat @@ -11,7 +11,9 @@ set ES_MAIN_CLASS=org.elasticsearch.xpack.watcher.trigger.schedule.tool.CronEval set ES_ADDITIONAL_SOURCES=x-pack-env;x-pack-watcher-env call "%~dp0elasticsearch-cli.bat" ^ %%* ^ - || exit /b 1 + || goto exit endlocal endlocal +:exit +exit /b %ERRORLEVEL%