Skip to content

Commit 6942858

Browse files
committed
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 dfecb25)
1 parent f7a430c commit 6942858

17 files changed

+46
-12
lines changed

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@ indent_style = space
88
indent_size = 4
99
trim_trailing_whitespace = true
1010
insert_final_newline = true
11+
12+
[*.bat]
13+
indent_size = 2

distribution/src/bin/elasticsearch-cli.bat

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,5 @@ if defined ES_ADDITIONAL_CLASSPATH_DIRECTORIES (
2121
-cp "%ES_CLASSPATH%" ^
2222
"%ES_MAIN_CLASS%" ^
2323
%*
24+
25+
exit /b %ERRORLEVEL%

distribution/src/bin/elasticsearch-keystore.bat

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ setlocal enableextensions
66
set ES_MAIN_CLASS=org.elasticsearch.common.settings.KeyStoreCli
77
call "%~dp0elasticsearch-cli.bat" ^
88
%%* ^
9-
|| exit /b 1
9+
|| goto exit
1010

1111
endlocal
1212
endlocal
13+
:exit
14+
exit /b %ERRORLEVEL%

distribution/src/bin/elasticsearch-plugin.bat

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ set ES_MAIN_CLASS=org.elasticsearch.plugins.PluginCli
77
set ES_ADDITIONAL_CLASSPATH_DIRECTORIES=lib/tools/plugin-cli
88
call "%~dp0elasticsearch-cli.bat" ^
99
%%* ^
10-
|| exit /b 1
10+
|| goto exit
11+
1112

1213
endlocal
1314
endlocal
15+
:exit
16+
exit /b %ERRORLEVEL%

distribution/src/bin/elasticsearch-service.bat

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,3 +252,5 @@ goto:eof
252252

253253
endlocal
254254
endlocal
255+
256+
exit /b %ERRORLEVEL%

distribution/src/bin/elasticsearch-shard.bat

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ setlocal enableextensions
66
set ES_MAIN_CLASS=org.elasticsearch.index.shard.ShardToolCli
77
call "%~dp0elasticsearch-cli.bat" ^
88
%%* ^
9-
|| exit /b 1
9+
|| goto exit
1010

1111
endlocal
1212
endlocal
13+
:exit
14+
exit /b %ERRORLEVEL%

distribution/src/bin/elasticsearch-translog.bat

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ setlocal enableextensions
66
set ES_MAIN_CLASS=org.elasticsearch.index.translog.TranslogToolCli
77
call "%~dp0elasticsearch-cli.bat" ^
88
%%* ^
9-
|| exit /b 1
9+
|| goto exit
1010

1111
endlocal
1212
endlocal
13+
:exit
14+
exit /b %ERRORLEVEL%

distribution/src/bin/elasticsearch.bat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,4 @@ cd /d "%ES_HOME%"
5555

5656
endlocal
5757
endlocal
58+
exit /b %ERRORLEVEL%

x-pack/plugin/security/src/main/bin/elasticsearch-certgen.bat

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ set ES_ADDITIONAL_SOURCES=x-pack-env;x-pack-security-env
1212
set ES_ADDITIONAL_CLASSPATH_DIRECTORIES=lib/tools/security-cli
1313
call "%~dp0elasticsearch-cli.bat" ^
1414
%%* ^
15-
|| exit /b 1
15+
|| goto exit
1616

1717
endlocal
1818
endlocal
19+
:exit
20+
exit /b %ERRORLEVEL%

x-pack/plugin/security/src/main/bin/elasticsearch-certutil.bat

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ set ES_ADDITIONAL_SOURCES=x-pack-env;x-pack-security-env
1212
set ES_ADDITIONAL_CLASSPATH_DIRECTORIES=lib/tools/security-cli
1313
call "%~dp0elasticsearch-cli.bat" ^
1414
%%* ^
15-
|| exit /b 1
15+
|| goto exit
1616

1717
endlocal
1818
endlocal
19+
:exit
20+
exit /b %ERRORLEVEL%

0 commit comments

Comments
 (0)