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 11, 2024
1 parent eb092ef commit 6d8a02f
Show file tree
Hide file tree
Showing 14 changed files with 59 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<prop name="--internal-remove-config" value=""/>
</props>
<packages>
<package name="banner" optional="true"/>
<package name="product.conf" optional="true"/>
<package name="misc.standalone"/>
<package name="org.jboss.as.standalone"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
_ ___ __ __________ ______
| | / (_) /___/ / ____/ /_ __ / ____/___ ________
| | /| / / / / __ / /_ / / / / / / / / __ \/ ___/ _ \
| |/ |/ / / / /_/ / __/ / / /_/ / / /___/ /_/ / / / __/
|__/|__/_/_/\__,_/_/ /_/\__, / \____/\____/_/ \___/
/____/
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" ?>

<package-spec xmlns="urn:jboss:galleon:package:2.0" name="banner">
</package-spec>
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
1 change: 1 addition & 0 deletions testsuite/domain/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@
</excluded-configs>
<excluded-packages>
<name>product.conf</name>
<name>banner</name>
</excluded-packages>
</feature-pack>
</feature-packs>
Expand Down
3 changes: 3 additions & 0 deletions testsuite/manualmode/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@
<version>${project.version}</version>
<excluded-packages>
<param>product.conf</param>
<name>banner</name>
</excluded-packages>
</feature-pack>
</feature-packs>
Expand Down Expand Up @@ -442,6 +443,7 @@
</included-packages>
<excluded-packages>
<name>product.conf</name>
<name>banner</name>
</excluded-packages>
</feature-pack>
</feature-packs>
Expand Down Expand Up @@ -543,6 +545,7 @@
</included-packages>
<excluded-packages>
<name>product.conf</name>
<name>banner</name>
</excluded-packages>
</feature-pack>
</feature-packs>
Expand Down
3 changes: 3 additions & 0 deletions testsuite/rbac/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
</config>
</included-configs>
<excludedPackages>
<name>banner</name>
<param>product.conf</param>
</excludedPackages>
</feature-pack>
Expand Down Expand Up @@ -332,6 +333,7 @@
<name>org.jboss.as.patching.cli</name>
</included-packages>
<excluded-packages>
<name>banner</name>
<name>product.conf</name>
</excluded-packages>
</feature-pack>
Expand Down Expand Up @@ -456,6 +458,7 @@
<name>org.jboss.as.patching.cli</name>
</included-packages>
<excluded-packages>
<name>banner</name>
<name>product.conf</name>
</excluded-packages>
</feature-pack>
Expand Down
3 changes: 3 additions & 0 deletions testsuite/standalone/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@
</config>
</included-configs>
<excluded-packages>
<name>banner</name>
<name>product.conf</name>
</excluded-packages>
</feature-pack>
Expand Down Expand Up @@ -307,6 +308,7 @@
<name>org.jboss.as.patching.cli</name>
</included-packages>
<excluded-packages>
<name>banner</name>
<name>product.conf</name>
</excluded-packages>
</feature-pack>
Expand Down Expand Up @@ -407,6 +409,7 @@
<name>org.jboss.as.patching.cli</name>
</included-packages>
<excluded-packages>
<name>banner</name>
<name>product.conf</name>
</excluded-packages>
</feature-pack>
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);
} 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 6d8a02f

Please sign in to comment.