Skip to content

Commit 9783d67

Browse files
authored
Merge pull request #32463 from Channyboy/32394-outputdir
Alternative resolution for resolving server output directory if `server.output.dir` is not set.
2 parents 7761783 + 523373b commit 9783d67

File tree

2 files changed

+49
-1
lines changed
  • dev
    • io.openliberty.microprofile.health.4.0.internal/src/io/openliberty/microprofile/health40/internal
    • io.openliberty.microprofile.health.internal.common/resources/io/openliberty/microprofile/health/resources

2 files changed

+49
-1
lines changed

dev/io.openliberty.microprofile.health.4.0.internal/src/io/openliberty/microprofile/health40/internal/HealthFileUtils.java

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,45 @@ public class HealthFileUtils {
3131
public static File getHealthDirFile() {
3232

3333
if (healthDirFile == null) {
34-
File serverConfigDirFile = new File(System.getProperty("server.output.dir"));
34+
35+
String serverOutputDir = System.getProperty("server.output.dir").trim();
36+
37+
File serverConfigDirFile;
38+
39+
/*
40+
* server.output.dir may not be set.
41+
* Construct the directory with WLP_OUTPUT_DIR and wlp.server.name or SERVER_NAME
42+
*/
43+
if (serverOutputDir == null || serverOutputDir.isEmpty()) {
44+
String wlpOutputDirEnv = System.getenv("WLP_OUTPUT_DIR").trim();
45+
46+
if (wlpOutputDirEnv == null || wlpOutputDirEnv.isEmpty()) {
47+
Tr.warning(tc, "file.healthcheck.health.directory.resolution.fail.CWMMH0102W");
48+
if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
49+
Tr.debug(tc,
50+
"The server was unable to resolve server.output.dir property nor the WLP_OUTPUT_DIR environment variable.");
51+
}
52+
return null;
53+
}
54+
55+
String serverName = System.getProperty("wlp.server.name").trim();
56+
57+
if (serverName == null || serverName.isEmpty()) {
58+
serverName = System.getenv("SERVER_NAME").trim();
59+
if (serverName == null || serverName.isEmpty()) {
60+
Tr.warning(tc, "file.healthcheck.health.directory.resolution.fail.CWMMH0102W");
61+
if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
62+
Tr.debug(tc,
63+
"The server was unable to resolve wlp.server.name property nor the SERVER_NAME environment variable.");
64+
}
65+
return null;
66+
}
67+
}
68+
69+
serverOutputDir = wlpOutputDirEnv + System.getProperty("file.separator") + serverName;
70+
}
71+
serverConfigDirFile = new File(serverOutputDir);
72+
3573
healthDirFile = new File(serverConfigDirFile, "health");
3674
}
3775

@@ -99,6 +137,13 @@ public static File getLiveFile() {
99137
public static boolean isValidSystem() throws IOException {
100138
healthDirFile = getHealthDirFile();
101139

140+
/*
141+
* Failed to resolve the Health directory File object. (i.e., could not resolve the path to create the path)
142+
*/
143+
if (healthDirFile == null) {
144+
return false;
145+
}
146+
102147
//Health Dir does not exist -> create and test write
103148
if (!healthDirFile.exists()) {
104149
if (!HealthFileUtils.createDirectory(healthDirFile)) {

dev/io.openliberty.microprofile.health.internal.common/resources/io/openliberty/microprofile/health/resources/Health.nlsprops

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ file.healthcheck.health.directory.write.fail.CWMMH0101W=CWMMH0101W: Unable to wr
7070
file.healthcheck.health.directory.write.fail.CWMMH0101W.explanation=The runtime requires write permissions to the /health directory to create the "live", "ready" and "started" files for the file-based health checks to function properly.
7171
file.healthcheck.health.directory.write.fail.CWMMH0101W.useraction=The user must identify the root cause of the permission issue.
7272

73+
file.healthcheck.health.directory.resolution.fail.CWMMH0102W=CWMMH0102W: The runtime cannot resolve the path for the /health directory. The file-based health check function will be disabled.
74+
file.healthcheck.health.directory.resolution.fail.CWMMH0102W.explanation=The runtime requires the internal server.output.dir property or WLP_OUTPUT_DIR environment variable to be set to determine the location of the /health directory.
75+
file.healthcheck.health.directory.resolution.fail.CWMMH0102W.useraction=Ensure that the WLP_OUTPUT_DIR environment variable is properly set.
7376

7477
file.healthcheck.file.name.conflict.CWMMH0105W=CWMMH0106W: The runtime has detected the presence of the following directory [{0}]. A file with the same name is required for the file-based health check function at this path. The file-based health check function will be disabled.
7578
file.healthcheck.file.name.conflict.CWMMH0105W.explanation=The file-based health checks require the creation and use of the files "live", "ready" and "started" in the /health directory. An existing directory with one of those names is already present in the /health directory which prevents the required files from being created.

0 commit comments

Comments
 (0)