Skip to content

Commit

Permalink
Exit batch files explictly using ERRORLEVEL (#29583)
Browse files Browse the repository at this point in the history
* 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 dfecb25)
  • Loading branch information
Mpdreamz committed Jan 25, 2019
1 parent f7a430c commit 6942858
Show file tree
Hide file tree
Showing 17 changed files with 46 additions and 12 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ indent_style = space
indent_size = 4
trim_trailing_whitespace = true
insert_final_newline = true

[*.bat]
indent_size = 2
2 changes: 2 additions & 0 deletions distribution/src/bin/elasticsearch-cli.bat
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@ if defined ES_ADDITIONAL_CLASSPATH_DIRECTORIES (
-cp "%ES_CLASSPATH%" ^
"%ES_MAIN_CLASS%" ^
%*

exit /b %ERRORLEVEL%
4 changes: 3 additions & 1 deletion distribution/src/bin/elasticsearch-keystore.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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%
5 changes: 4 additions & 1 deletion distribution/src/bin/elasticsearch-plugin.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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%
2 changes: 2 additions & 0 deletions distribution/src/bin/elasticsearch-service.bat
Original file line number Diff line number Diff line change
Expand Up @@ -252,3 +252,5 @@ goto:eof

endlocal
endlocal

exit /b %ERRORLEVEL%
4 changes: 3 additions & 1 deletion distribution/src/bin/elasticsearch-shard.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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%
4 changes: 3 additions & 1 deletion distribution/src/bin/elasticsearch-translog.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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%
1 change: 1 addition & 0 deletions distribution/src/bin/elasticsearch.bat
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,4 @@ cd /d "%ES_HOME%"

endlocal
endlocal
exit /b %ERRORLEVEL%
Original file line number Diff line number Diff line change
Expand Up @@ -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%
Original file line number Diff line number Diff line change
Expand Up @@ -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%
Original file line number Diff line number Diff line change
Expand Up @@ -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%
Original file line number Diff line number Diff line change
Expand Up @@ -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%
Original file line number Diff line number Diff line change
Expand Up @@ -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%
Original file line number Diff line number Diff line change
Expand Up @@ -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%
4 changes: 3 additions & 1 deletion x-pack/plugin/security/src/main/bin/elasticsearch-users.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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%
1 change: 1 addition & 0 deletions x-pack/plugin/sql/src/main/bin/elasticsearch-sql-cli.bat
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ set CLI_JAR=%ES_HOME%/bin/*

endlocal
endlocal
exit /b %ERRORLEVEL%
Original file line number Diff line number Diff line change
Expand Up @@ -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%

0 comments on commit 6942858

Please sign in to comment.