Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions server/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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);
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}

Expand Down Expand Up @@ -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)
* <p>
Expand Down Expand Up @@ -110,7 +119,7 @@ public static Dictionary<Object,Object> getSystemProperties() {
return SYSTEM_PROPERTIES;
}

public static void init() {
public static void init(boolean isTerminalAvailable) {
BootstrapInfo.terminalAvailable = isTerminalAvailable;
}

}