Skip to content

Commit 61c3158

Browse files
committed
Log system information early during startup (elastic#124926)
Information about the system, and in particular the running JVM, is logged relatively late in startup. When problems occur in low level initialization, it is often useful to have this information. This commit moves logging of system information to right after logging has been initialized. Note that it no longer utilizes the JvmInfo class as most was already easily available and the static init of JvmInfo does a lot. (cherry picked from commit 789eb2f) # Conflicts: # server/src/main/java/org/elasticsearch/bootstrap/Elasticsearch.java # server/src/main/java/org/elasticsearch/node/NodeConstruction.java
1 parent ace6505 commit 61c3158

File tree

5 files changed

+38
-42
lines changed

5 files changed

+38
-42
lines changed

distribution/src/bin/elasticsearch-cli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ exec \
1919
-Des.path.home="$ES_HOME" \
2020
-Des.path.conf="$ES_PATH_CONF" \
2121
-Des.distribution.type="$ES_DISTRIBUTION_TYPE" \
22+
-Des.java.type="$JAVA_TYPE" \
2223
-cp "$LAUNCHER_CLASSPATH" \
2324
org.elasticsearch.launcher.CliToolLauncher \
2425
"$@"

distribution/src/bin/elasticsearch-cli.bat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ set LAUNCHER_CLASSPATH=%ES_HOME%/lib/*;%ES_HOME%/lib/cli-launcher/*
1818
-Des.path.home="%ES_HOME%" ^
1919
-Des.path.conf="%ES_PATH_CONF%" ^
2020
-Des.distribution.type="%ES_DISTRIBUTION_TYPE%" ^
21+
-Des.java.type="%JAVA_TYPE%" ^
2122
-cp "%LAUNCHER_CLASSPATH%" ^
2223
org.elasticsearch.launcher.CliToolLauncher ^
2324
%*

server/src/main/java/org/elasticsearch/bootstrap/Elasticsearch.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.apache.logging.log4j.Logger;
1414
import org.apache.logging.log4j.core.LoggerContext;
1515
import org.apache.logging.log4j.core.config.Configurator;
16+
import org.apache.lucene.util.Constants;
1617
import org.apache.lucene.util.StringHelper;
1718
import org.apache.lucene.util.VectorUtil;
1819
import org.elasticsearch.Build;
@@ -54,6 +55,7 @@
5455
import java.io.InputStream;
5556
import java.io.PrintStream;
5657
import java.lang.invoke.MethodHandles;
58+
import java.lang.management.ManagementFactory;
5759
import java.lang.reflect.InvocationTargetException;
5860
import java.nio.file.Files;
5961
import java.nio.file.Path;
@@ -62,6 +64,7 @@
6264
import java.util.HashMap;
6365
import java.util.HashSet;
6466
import java.util.List;
67+
import java.util.Locale;
6568
import java.util.Map;
6669
import java.util.Objects;
6770
import java.util.Set;
@@ -158,6 +161,9 @@ private static Bootstrap initPhase1() {
158161
* <p> Phase 2 consists of everything that must occur up to and including security manager initialization.
159162
*/
160163
private static void initPhase2(Bootstrap bootstrap) throws IOException {
164+
// always start by dumping what we know about the process to the log
165+
logSystemInfo();
166+
161167
final ServerArgs args = bootstrap.args();
162168
final SecureSettings secrets = args.secrets();
163169
bootstrap.setSecureSettings(secrets);
@@ -257,6 +263,35 @@ private static void initPhase2(Bootstrap bootstrap) throws IOException {
257263
bootstrap.setPluginsLoader(pluginsLoader);
258264
}
259265

266+
private static void logSystemInfo() {
267+
final Logger logger = LogManager.getLogger(Elasticsearch.class);
268+
logger.info(
269+
"version[{}], pid[{}], build[{}/{}/{}], OS[{}/{}/{}], JVM[{}/{}/{}/{}]",
270+
Build.current().qualifiedVersion(),
271+
ProcessHandle.current().pid(),
272+
Build.current().type().displayName(),
273+
Build.current().hash(),
274+
Build.current().date(),
275+
Constants.OS_NAME,
276+
Constants.OS_VERSION,
277+
Constants.OS_ARCH,
278+
Constants.JVM_VENDOR,
279+
Constants.JVM_NAME,
280+
System.getProperty("java.version"),
281+
Runtime.version().toString()
282+
);
283+
boolean isBundledJdk = System.getProperty("es.java.type", "").equals("bundled JDK");
284+
logger.info("JVM home [{}], using bundled JDK [{}]", System.getProperty("java.home"), isBundledJdk);
285+
logger.info("JVM arguments {}", ManagementFactory.getRuntimeMXBean().getInputArguments());
286+
logger.info("Default Locale [{}]", Locale.getDefault());
287+
if (Build.current().isProductionRelease() == false) {
288+
logger.warn(
289+
"version [{}] is a pre-release version of Elasticsearch and is not suitable for production",
290+
Build.current().qualifiedVersion()
291+
);
292+
}
293+
}
294+
260295
/**
261296
* @throws IllegalStateException if entitlements aren't functioning properly.
262297
*/

server/src/main/java/org/elasticsearch/monitor/jvm/JvmInfo.java

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,11 @@
99

1010
package org.elasticsearch.monitor.jvm;
1111

12-
import org.apache.lucene.util.Constants;
1312
import org.elasticsearch.TransportVersions;
1413
import org.elasticsearch.common.io.stream.StreamInput;
1514
import org.elasticsearch.common.io.stream.StreamOutput;
1615
import org.elasticsearch.common.io.stream.Writeable;
1716
import org.elasticsearch.common.unit.ByteSizeValue;
18-
import org.elasticsearch.core.PathUtils;
19-
import org.elasticsearch.core.SuppressForbidden;
2017
import org.elasticsearch.node.ReportingService;
2118
import org.elasticsearch.xcontent.XContentBuilder;
2219

@@ -168,19 +165,8 @@ public class JvmInfo implements ReportingService.Info {
168165
);
169166
}
170167

171-
@SuppressForbidden(reason = "PathUtils#get")
172168
private static boolean usingBundledJdk() {
173-
/*
174-
* We are using the bundled JDK if java.home is the jdk sub-directory of our working directory. This is because we always set
175-
* the working directory of Elasticsearch to home, and the bundled JDK is in the jdk sub-directory there.
176-
*/
177-
final String javaHome = System.getProperty("java.home");
178-
final String userDir = System.getProperty("user.dir");
179-
if (Constants.MAC_OS_X) {
180-
return PathUtils.get(javaHome).equals(PathUtils.get(userDir).resolve("jdk.app/Contents/Home").toAbsolutePath());
181-
} else {
182-
return PathUtils.get(javaHome).equals(PathUtils.get(userDir).resolve("jdk").toAbsolutePath());
183-
}
169+
return System.getProperty("es.java.type", "").equals("bundled JDK");
184170
}
185171

186172
public static JvmInfo jvmInfo() {

server/src/main/java/org/elasticsearch/node/NodeConstruction.java

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212
import org.apache.logging.log4j.LogManager;
1313
import org.apache.logging.log4j.Logger;
1414
import org.apache.lucene.search.IndexSearcher;
15-
import org.apache.lucene.util.Constants;
1615
import org.apache.lucene.util.SetOnce;
17-
import org.elasticsearch.Build;
1816
import org.elasticsearch.ElasticsearchException;
1917
import org.elasticsearch.TransportVersion;
2018
import org.elasticsearch.action.ActionModule;
@@ -229,7 +227,6 @@
229227
import java.util.IdentityHashMap;
230228
import java.util.LinkedHashSet;
231229
import java.util.List;
232-
import java.util.Locale;
233230
import java.util.Map;
234231
import java.util.Objects;
235232
import java.util.Optional;
@@ -410,30 +407,6 @@ private Settings createEnvironment(Environment initialEnvironment, NodeServicePr
410407
DeprecationLogger.initialize(envSettings);
411408

412409
JvmInfo jvmInfo = JvmInfo.jvmInfo();
413-
logger.info(
414-
"version[{}], pid[{}], build[{}/{}/{}], OS[{}/{}/{}], JVM[{}/{}/{}/{}]",
415-
Build.current().qualifiedVersion(),
416-
jvmInfo.pid(),
417-
Build.current().type().displayName(),
418-
Build.current().hash(),
419-
Build.current().date(),
420-
Constants.OS_NAME,
421-
Constants.OS_VERSION,
422-
Constants.OS_ARCH,
423-
Constants.JVM_VENDOR,
424-
Constants.JVM_NAME,
425-
Constants.JAVA_VERSION,
426-
Constants.JVM_VERSION
427-
);
428-
logger.info("JVM home [{}], using bundled JDK [{}]", System.getProperty("java.home"), jvmInfo.getUsingBundledJdk());
429-
logger.info("JVM arguments {}", Arrays.toString(jvmInfo.getInputArguments()));
430-
logger.info("Default Locale [{}]", Locale.getDefault());
431-
if (Build.current().isProductionRelease() == false) {
432-
logger.warn(
433-
"version [{}] is a pre-release version of Elasticsearch and is not suitable for production",
434-
Build.current().qualifiedVersion()
435-
);
436-
}
437410
if (Environment.PATH_SHARED_DATA_SETTING.exists(envSettings)) {
438411
// NOTE: this must be done with an explicit check here because the deprecation property on a path setting will
439412
// cause ES to fail to start since logging is not yet initialized on first read of the setting

0 commit comments

Comments
 (0)