diff --git a/server/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java b/server/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java index 00ccac0d4bf04..501bc8470c4a8 100644 --- a/server/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java +++ b/server/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java @@ -314,9 +314,11 @@ static void init( final Path pidFile, final boolean quiet, final Environment initialEnv) throws BootstrapException, NodeValidationException, UserException { - // force the class initializer for BootstrapInfo to run before - // the security manager is installed - BootstrapInfo.init(); + // If this is true, we allow output to be written to the console user (not the logs) for exceptional cases + var hasConsole = foreground && (quiet == false); + + // force the class initializer for BootstrapInfo to run before the security manager is installed + BootstrapInfo.init(hasConsole); INSTANCE = new Bootstrap(); @@ -328,6 +330,11 @@ static void init( final Runnable sysOutCloser = getSysOutCloser(); final Runnable sysErrorCloser = getSysErrorCloser(); + if (hasConsole) { + // Load the default terminal now, so that it references the original stdout stream rather than the logging stream + var ignore = Terminal.DEFAULT; + } + LogConfigurator.setNodeName(Node.NODE_NAME_SETTING.get(environment.settings())); try { LogConfigurator.configure(environment); @@ -342,10 +349,8 @@ static void init( } } - try { - final boolean closeStandardStreams = (foreground == false) || quiet; - if (closeStandardStreams) { + if (hasConsole == false) { final Logger rootLogger = LogManager.getRootLogger(); final Appender maybeConsoleAppender = Loggers.findAppender(rootLogger, ConsoleAppender.class); if (maybeConsoleAppender != null) { diff --git a/server/src/main/java/org/elasticsearch/bootstrap/BootstrapInfo.java b/server/src/main/java/org/elasticsearch/bootstrap/BootstrapInfo.java index 5c14450b3c76f..6185cace375ee 100644 --- a/server/src/main/java/org/elasticsearch/bootstrap/BootstrapInfo.java +++ b/server/src/main/java/org/elasticsearch/bootstrap/BootstrapInfo.java @@ -19,6 +19,8 @@ @SuppressForbidden(reason = "exposes read-only view of system properties") public final class BootstrapInfo { + private static boolean terminalAvailable; + /** no instantiation */ private BootstrapInfo() {} @@ -46,6 +48,13 @@ public static boolean isSystemCallFilterInstalled() { return Natives.isSystemCallFilterInstalled(); } + /** + * Returns true if terminal (non logging) output is available + */ + public static boolean isTerminalOutputAvailable() { + return terminalAvailable; + } + /** * codebase location for untrusted scripts (provide some additional safety) *
@@ -110,7 +119,7 @@ public static Dictionary