Skip to content

Commit

Permalink
[WFCORE-4917]: Experimental - Provide a cool boot banner.
Browse files Browse the repository at this point in the history
* Add support for a cool ASCII art banner via a banner.txt in the $JBOSS_HOME/bin directory.

Jira: https://issues.redhat.com/browse/WFCORE-4917

Signed-off-by: Emmanuel Hugonnet <[email protected]>
  • Loading branch information
ehsavoie committed Mar 13, 2024
1 parent eb092ef commit 2eb6a7e
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
</resources>

<dependencies/>
</module>
</module>
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@ public HostControllerEnvironment(Map<String, String> hostSystemProperties, boole
this.hostControllerUUID = uuid;
this.backupDomainFiles = backupDomainFiles;
this.useCachedDc = useCachedDc;
ProductConfig.getBannerFile(productConfig, homeDir.getAbsolutePath());
this.productConfig = productConfig;
// Note the java.security.manager property shouldn't be set, but we'll check to ensure the security manager should be enabled
this.securityManagerEnabled = securityManagerEnabled || isJavaSecurityManagerConfigured(hostSystemProperties);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ public void start(StartContext context) throws StartException {
// processState.setStarting();
final ProductConfig config = environment.getProductConfig();
final String prettyVersion = config.getPrettyVersionString();
ServerLogger.AS_ROOT_LOGGER.serverStarting(prettyVersion);
final String banner = environment.getStability() == org.jboss.as.version.Stability.EXPERIMENTAL ? config.getBanner() : "";
ServerLogger.AS_ROOT_LOGGER.serverStarting(prettyVersion, banner);
if (System.getSecurityManager() != null) {
ServerLogger.AS_ROOT_LOGGER.securityManagerEnabled();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ public synchronized void start(final StartContext context) throws StartException
final ServerEnvironment serverEnvironment = configuration.getServerEnvironment();
final ProductConfig config = serverEnvironment.getProductConfig();
final String prettyVersion = config.getPrettyVersionString();
ServerLogger.AS_ROOT_LOGGER.serverStarting(prettyVersion);
final String banner = serverEnvironment.getStability() == org.jboss.as.version.Stability.EXPERIMENTAL ? config.getBanner() : "";
ServerLogger.AS_ROOT_LOGGER.serverStarting(prettyVersion, banner);
if (System.getSecurityManager() != null) {
ServerLogger.AS_ROOT_LOGGER.securityManagerEnabled();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,7 @@ public ServerEnvironment(final String hostControllerName, final Properties props
throw ServerLogger.ROOT_LOGGER.couldNotObtainServerUuidFile(ex, filePath);
}
this.serverUUID = uuid;
ProductConfig.getBannerFile(productConfig, homeDir.getAbsolutePath());
this.productConfig = productConfig;

// Keep a copy of the original properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,10 +317,11 @@ public interface ServerLogger extends BasicLogger {
* Logs an informational message indicating the server is starting.
*
* @param prettyVersion the server version.
* @param banner the server ACII banner.
*/
@LogMessage(level = INFO)
@Message(id = 49, value = "%s starting")
void serverStarting(String prettyVersion);
@Message(id = 49, value = "%s starting%s")
void serverStarting(String prettyVersion, String banner);

/**
* Logs an informational message indicating the server is stopped.
Expand Down
31 changes: 28 additions & 3 deletions version/src/main/java/org/jboss/as/version/ProductConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.io.Serializable;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.AccessController;
import java.security.PrivilegedAction;
Expand All @@ -34,19 +35,20 @@ public class ProductConfig implements Serializable {

private final String name;
private final String version;
private String banner;
private final String consoleSlot;
private final Stability defaultStability;
private final Set<Stability> stabilities;
private boolean isProduct;

public static ProductConfig fromFilesystemSlot(ModuleLoader loader, String home, Map<?, ?> providedProperties) {
return new ProductConfig(loader, getProductConfProperties(home), providedProperties);
return new ProductConfig(loader, home, getProductConfProperties(home), providedProperties);
}

public static ProductConfig fromKnownSlot(String slot, ModuleLoader loader, Map<?, ?> providedProperties) {
return new ProductConfig(loader, new ProductConfProps(slot), providedProperties);
return new ProductConfig(loader, null, new ProductConfProps(slot), providedProperties);
}
private ProductConfig(ModuleLoader loader, ProductConfProps productConfProps, Map<?, ?> providedProperties) {
private ProductConfig(ModuleLoader loader, String home, ProductConfProps productConfProps, Map<?, ?> providedProperties) {
String productName = null;
String projectName = null;
String productVersion = null;
Expand Down Expand Up @@ -81,6 +83,7 @@ private ProductConfig(ModuleLoader loader, ProductConfProps productConfProps, Ma
minStability = Stability.fromString(minStabilityValue);
}
}
getBannerFile(this, home);
}

setSystemProperties(productConfProps.miscProperties, providedProperties);
Expand All @@ -97,6 +100,19 @@ private ProductConfig(ModuleLoader loader, ProductConfProps productConfProps, Ma
this.stabilities = EnumSet.range(maxStability, minStability);
}

public static void getBannerFile(ProductConfig config, String home) {
if (home != null) {
Path bannerPath = Paths.get(home, "bin", "banner.txt");
if (bannerPath != null && Files.exists(bannerPath)) {
try {
config.banner = System.lineSeparator() + Files.readString(bannerPath, StandardCharsets.UTF_8);
} catch (Exception e) {
// Don't care
}
}
}
}

private static String getProductConf(String home) {
final String defaultVal = home + File.separator + "bin" + File.separator + "product.conf";
PrivilegedAction<String> action = new PrivilegedAction<String>() {
Expand Down Expand Up @@ -133,6 +149,7 @@ public ProductConfig(final String productName, final String productVersion, fina
this.consoleSlot = consoleSlot;
this.defaultStability = Stability.DEFAULT;
this.stabilities = EnumSet.of(this.defaultStability);
this.banner = null;
}

public String getProductName() {
Expand Down Expand Up @@ -167,6 +184,14 @@ public Set<Stability> getStabilitySet() {
return this.stabilities;
}

/**
* The product ASCII banner defined in $JBOSS_HOME\bin\banner.txt using \n as line ending.
* @return the ASCII banner.
*/
public String getBanner() {
return banner;
}

public String getPrettyVersionString() {
if (name != null) {
return String.format("%s %s (WildFly Core %s)", name, version, Version.AS_VERSION);
Expand Down

0 comments on commit 2eb6a7e

Please sign in to comment.