@@ -86,7 +86,7 @@ public static Installation installPackage(Shell sh, Distribution distribution) t
86
86
public static Installation installPackage (Shell sh , Distribution distribution , @ Nullable Predicate <String > outputPredicate )
87
87
throws IOException {
88
88
String systemJavaHome = sh .run ("echo $SYSTEM_JAVA_HOME" ).stdout ().trim ();
89
- if (distribution . hasJdk == false ) {
89
+ if (requiresExplicitJavaHome ( distribution ) ) {
90
90
sh .getEnv ().put ("ES_JAVA_HOME" , systemJavaHome );
91
91
}
92
92
final Result result = runPackageManager (distribution , sh , PackageManagerCommand .INSTALL );
@@ -98,7 +98,7 @@ public static Installation installPackage(Shell sh, Distribution distribution, @
98
98
}
99
99
Installation installation = Installation .ofPackage (sh , distribution );
100
100
installation .setElasticPassword (captureElasticPasswordFromOutput (result ));
101
- if (distribution . hasJdk == false ) {
101
+ if (requiresExplicitJavaHome ( distribution ) ) {
102
102
Files .write (installation .envFile , List .of ("ES_JAVA_HOME=" + systemJavaHome ), StandardOpenOption .APPEND );
103
103
}
104
104
@@ -109,6 +109,15 @@ public static Installation installPackage(Shell sh, Distribution distribution, @
109
109
return installation ;
110
110
}
111
111
112
+ private static boolean requiresExplicitJavaHome (Distribution distribution ) {
113
+ if (distribution .hasJdk == false ) {
114
+ return true ;
115
+ }
116
+ Version version = Version .fromString (distribution .baseVersion );
117
+ boolean requiresPatch = Platforms .isUbuntu24 () && (version .onOrAfter (Version .V_8_0_0 ) && version .onOrBefore (Version .V_8_4_3 ));
118
+ return requiresPatch ;
119
+ }
120
+
112
121
private static String captureElasticPasswordFromOutput (Result result ) {
113
122
return Arrays .stream (result .stdout ().split (System .lineSeparator ()))
114
123
.filter (l -> l .contains ("The generated password for the elastic built-in superuser is : " ))
@@ -123,7 +132,20 @@ public static Installation upgradePackage(Shell sh, Distribution distribution) t
123
132
throw new RuntimeException ("Upgrading distribution " + distribution + " failed: " + result );
124
133
}
125
134
126
- return Installation .ofPackage (sh , distribution );
135
+ Installation installation = Installation .ofPackage (sh , distribution );
136
+ if (requiresExplicitJavaHome (distribution )) {
137
+ String systemJavaHome = sh .run ("echo $SYSTEM_JAVA_HOME" ).stdout ().trim ();
138
+ Files .write (installation .envFile , List .of ("ES_JAVA_HOME=" + systemJavaHome ), StandardOpenOption .APPEND );
139
+ } else {
140
+ // Explicitly remove the line if added for previous installation
141
+ Files .write (
142
+ installation .envFile ,
143
+ Files .readAllLines (installation .envFile ).stream ().filter (line -> line .startsWith ("ES_JAVA_HOME" ) == false ).toList (),
144
+ StandardOpenOption .WRITE ,
145
+ StandardOpenOption .TRUNCATE_EXISTING
146
+ );
147
+ }
148
+ return installation ;
127
149
}
128
150
129
151
public static Installation forceUpgradePackage (Shell sh , Distribution distribution ) throws IOException {
0 commit comments