Skip to content

Commit 2c6debc

Browse files
authored
Restore setting up temp dir for windows service (#44541) (#44662)
In #41913 setting up the temp dir for ES was moved from the env script to individual cli scripts. However, moving it to the windows service cli was missed. This commit restores setting up the temp dir for the windows service control script.
1 parent 367aa48 commit 2c6debc

File tree

3 files changed

+23
-10
lines changed

3 files changed

+23
-10
lines changed

buildSrc/src/main/groovy/org/elasticsearch/gradle/vagrant/VagrantTestPlugin.groovy

+18-9
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ class VagrantTestPlugin implements Plugin<Project> {
312312
test_args=( "\$@" )
313313
fi
314314
315-
"${-> convertPath(project, linuxGradleJdk.toString()) }"/bin/java -cp "\$PACKAGING_TESTS/*" org.elasticsearch.packaging.VMTestRunner "\${test_args[@]}"
315+
"${-> convertLinuxPath(project, linuxGradleJdk.toString()) }"/bin/java -cp "\$PACKAGING_TESTS/*" org.elasticsearch.packaging.VMTestRunner "\${test_args[@]}"
316316
"""
317317
}
318318
Task createWindowsRunnerScript = project.tasks.create('createWindowsRunnerScript', FileContentsTask) {
@@ -321,13 +321,19 @@ class VagrantTestPlugin implements Plugin<Project> {
321321
// the use of $args rather than param() here is deliberate because the syntax for array (multivalued) parameters is likely
322322
// a little trappy for those unfamiliar with powershell
323323
contents """\
324-
if (\$args.Count -eq 0) {
325-
\$testArgs = @("${-> project.extensions.esvagrant.testClass}")
326-
} else {
327-
\$testArgs = \$args
324+
try {
325+
if (\$args.Count -eq 0) {
326+
\$testArgs = @("${-> project.extensions.esvagrant.testClass}")
327+
} else {
328+
\$testArgs = \$args
329+
}
330+
& "${-> convertWindowsPath(project, windowsGradleJdk.toString()) }/bin/java" -cp "\$Env:PACKAGING_TESTS/*" org.elasticsearch.packaging.VMTestRunner @testArgs
331+
exit \$LASTEXITCODE
332+
} catch {
333+
# catch if we have a failure to even run the script at all above, equivalent to set -e, sort of
334+
echo "\$_.Exception.Message"
335+
exit 1
328336
}
329-
& "${-> convertPath(project, windowsGradleJdk.toString()) }"/bin/java -cp "\$Env:PACKAGING_TESTS/*" org.elasticsearch.packaging.VMTestRunner @testArgs
330-
exit \$LASTEXITCODE
331337
"""
332338
}
333339

@@ -610,7 +616,7 @@ class VagrantTestPlugin implements Plugin<Project> {
610616
// https://github.com/hashicorp/vagrant/blob/9c299a2a357fcf87f356bb9d56e18a037a53d138/plugins/communicators/winrm/communicator.rb#L195-L225
611617
// https://devops-collective-inc.gitbooks.io/secrets-of-powershell-remoting/content/manuscript/accessing-remote-computers.html
612618
javaPackagingTest.command = 'winrm'
613-
javaPackagingTest.args = ['--elevated', '--command', 'powershell -File "$Env:PACKAGING_TESTS/run-tests.ps1"']
619+
javaPackagingTest.args = ['--elevated', '--command', '& "$Env:PACKAGING_TESTS/run-tests.ps1"; exit $LASTEXITCODE']
614620
}
615621

616622
TaskExecutionAdapter javaPackagingReproListener = createReproListener(project, javaPackagingTest.path)
@@ -643,7 +649,10 @@ class VagrantTestPlugin implements Plugin<Project> {
643649
}
644650

645651
// convert the given path from an elasticsearch repo path to a VM path
646-
private String convertPath(Project project, String path) {
652+
private String convertLinuxPath(Project project, String path) {
647653
return "/elasticsearch/" + project.rootDir.toPath().relativize(Paths.get(path));
648654
}
655+
private String convertWindowsPath(Project project, String path) {
656+
return "C:\\elasticsearch\\" + project.rootDir.toPath().relativize(Paths.get(path)).toString().replace('/', '\\');
657+
}
649658
}

distribution/src/bin/elasticsearch-service.bat

+4
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ if exist "%JAVA_HOME%\bin\server\jvm.dll" (
106106
)
107107

108108
:foundJVM
109+
if not defined ES_TMPDIR (
110+
for /f "tokens=* usebackq" %%a in (`CALL %JAVA% -cp "!ES_CLASSPATH!" "org.elasticsearch.tools.launchers.TempDirectory"`) do set ES_TMPDIR=%%a
111+
)
112+
109113
set ES_JVM_OPTIONS=%ES_PATH_CONF%\jvm.options
110114

111115
if not "%ES_JAVA_OPTS%" == "" set ES_JAVA_OPTS=%ES_JAVA_OPTS: =;%

qa/vagrant/src/main/java/org/elasticsearch/packaging/test/WindowsServiceTestCase.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ private void assertExit(Result result, String script, int exitCode) {
9292
Result logs = sh.run("$files = Get-ChildItem \"" + installation.logs + "\\elasticsearch.log\"; " +
9393
"Write-Output $files; " +
9494
"foreach ($file in $files) {" +
95-
"Write-Output \"$file\"; " +
95+
"Write-Output \"$file\"; " +
9696
"Get-Content \"$file\" " +
9797
"}");
9898
logger.error(logs.stdout);

0 commit comments

Comments
 (0)