Skip to content

Commit

Permalink
[AS7-6380] Read system properties from product.conf. Only set each if…
Browse files Browse the repository at this point in the history
… not specified on command-line or in domain/standalone.conf

Make sure product.conf properties get added to ServerEnvironment.primordialProperties
  • Loading branch information
kabir authored and bstansberry committed Feb 6, 2013
1 parent c3ce3d2 commit 968da93
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public static ParsedOptions determineEnvironment(String[] args, Properties syste
clientArguments.add(arg);
} else if (CommandLineConstants.VERSION.equals(arg) || CommandLineConstants.SHORT_VERSION.equals(arg)
|| CommandLineConstants.OLD_VERSION.equals(arg) || CommandLineConstants.OLD_SHORT_VERSION.equals(arg)) {
productConfig = new ProductConfig(Module.getBootModuleLoader(), SecurityActions.getSystemProperty(ServerEnvironment.HOME_DIR));
productConfig = new ProductConfig(Module.getBootModuleLoader(), SecurityActions.getSystemProperty(ServerEnvironment.HOME_DIR), null);
System.out.println(productConfig.getPrettyVersionString());
return null;
} else if (CommandLineConstants.HELP.equals(arg) || CommandLineConstants.SHORT_HELP.equals(arg) || CommandLineConstants.OLD_HELP.equals(arg)) {
Expand Down Expand Up @@ -273,7 +273,7 @@ public static ParsedOptions determineEnvironment(String[] args, Properties syste
}

String hostControllerName = null; // No host controller unless in domain mode.
productConfig = new ProductConfig(Module.getBootModuleLoader(), SecurityActions.getSystemProperty(ServerEnvironment.HOME_DIR));
productConfig = new ProductConfig(Module.getBootModuleLoader(), SecurityActions.getSystemProperty(ServerEnvironment.HOME_DIR), systemProperties);
ret.environment = new ServerEnvironment(hostControllerName, systemProperties, systemEnvironment, appClientConfig, null, launchType, null, productConfig);
return ret;
}
Expand Down
1 change: 0 additions & 1 deletion build/src/main/resources/bin/domain.conf
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ fi
if [ "x$JAVA_OPTS" = "x" ]; then
JAVA_OPTS="-Xms64m -Xmx512m -XX:MaxPermSize=256m -Djava.net.preferIPv4Stack=true"
JAVA_OPTS="$JAVA_OPTS -Djboss.modules.system.pkgs=$JBOSS_MODULES_SYSTEM_PKGS -Djava.awt.headless=true"
JAVA_OPTS="$JAVA_OPTS -Djboss.domain.default.config=domain.xml -Djboss.host.default.config=host.xml"
else
echo "JAVA_OPTS already set in environment; overriding default settings with values: $JAVA_OPTS"
fi
Expand Down
3 changes: 0 additions & 3 deletions build/src/main/resources/bin/domain.conf.bat
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ rem # Make Byteman classes visible in all module loaders
rem # This is necessary to inject Byteman rules into AS7 deployments
set "JAVA_OPTS=%JAVA_OPTS% -Djboss.modules.system.pkgs=org.jboss.byteman"

rem # Set the default configuration files to use if -c, --domain-config or --host-config are not used
set "JAVA_OPTS=%JAVA_OPTS% -Djboss.domain.default.config=domain.xml -Djboss.host.default.config=host.xml"

rem # Use JBoss Modules lockless mode
rem set "JAVA_OPTS=%JAVA_OPTS% -Djboss.modules.lockless=true"

Expand Down
1 change: 0 additions & 1 deletion build/src/main/resources/bin/standalone.conf
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ fi
if [ "x$JAVA_OPTS" = "x" ]; then
JAVA_OPTS="-Xms64m -Xmx512m -XX:MaxPermSize=256m -Djava.net.preferIPv4Stack=true"
JAVA_OPTS="$JAVA_OPTS -Djboss.modules.system.pkgs=$JBOSS_MODULES_SYSTEM_PKGS -Djava.awt.headless=true"
JAVA_OPTS="$JAVA_OPTS -Djboss.server.default.config=standalone.xml"
else
echo "JAVA_OPTS already set in environment; overriding default settings with values: $JAVA_OPTS"
fi
Expand Down
3 changes: 0 additions & 3 deletions build/src/main/resources/bin/standalone.conf.bat
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ rem # Make Byteman classes visible in all module loaders
rem # This is necessary to inject Byteman rules into AS7 deployments
set "JAVA_OPTS=%JAVA_OPTS% -Djboss.modules.system.pkgs=org.jboss.byteman"

rem # Set the default configuration file to use if -c or --server-config are not used
set "JAVA_OPTS=%JAVA_OPTS% -Djboss.server.default.config=standalone.xml"

rem # Sample JPDA settings for remote socket debugging
rem set "JAVA_OPTS=%JAVA_OPTS% -agentlib:jdwp=transport=dt_socket,address=8787,server=y,suspend=n"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ private HostControllerEnvironment createHostControllerEnvironment() {
RunningMode initialRunningMode = runningModeControl.getRunningMode();
boolean backupDomainFiles = false;
boolean useCachedDc = false;
ProductConfig productConfig = new ProductConfig(null, "");
ProductConfig productConfig = new ProductConfig(null, "", props);
return new HostControllerEnvironment(props, isRestart, modulePath, processControllerAddress, processControllerPort,
hostControllerAddress, hostControllerPort, defaultJVM, domainConfig, initialDomainConfig, hostConfig, initialHostConfig,
initialRunningMode, backupDomainFiles, useCachedDc, productConfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ private static HostControllerEnvironment determineEnvironment(String[] args) {
return null;
}
}
productConfig = new ProductConfig(Module.getBootModuleLoader(), SecurityActions.getSystemProperty(HostControllerEnvironment.HOME_DIR));
productConfig = new ProductConfig(Module.getBootModuleLoader(), SecurityActions.getSystemProperty(HostControllerEnvironment.HOME_DIR), hostSystemProperties);
return new HostControllerEnvironment(hostSystemProperties, isRestart, modulePath, pmAddress, pmPort,
pcSocketConfig.getBindAddress(), pcSocketConfig.getBindPort(), defaultJVM,
domainConfig, initialDomainConfig, hostConfig, initialHostConfig, initialRunningMode, backupDomainFiles, cachedDc, productConfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ private static boolean handleHelpOrVersion(String arg, String jbossHome) {
return true;
} else if (CommandLineConstants.VERSION.equals(arg) || CommandLineConstants.SHORT_VERSION.equals(arg)
|| CommandLineConstants.OLD_VERSION.equals(arg) || CommandLineConstants.OLD_SHORT_VERSION.equals(arg)) {
System.out.println(new ProductConfig(Module.getBootModuleLoader(), jbossHome).getPrettyVersionString());
System.out.println(new ProductConfig(Module.getBootModuleLoader(), jbossHome, null).getPrettyVersionString());
return true;
}
return false;
Expand Down
4 changes: 2 additions & 2 deletions server/src/main/java/org/jboss/as/server/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public static ServerEnvironment determineEnvironment(String[] args, Properties s
try {
if (CommandLineConstants.VERSION.equals(arg) || CommandLineConstants.SHORT_VERSION.equals(arg)
|| CommandLineConstants.OLD_VERSION.equals(arg) || CommandLineConstants.OLD_SHORT_VERSION.equals(arg)) {
productConfig = new ProductConfig(Module.getBootModuleLoader(), SecurityActions.getSystemProperty(ServerEnvironment.HOME_DIR));
productConfig = new ProductConfig(Module.getBootModuleLoader(), SecurityActions.getSystemProperty(ServerEnvironment.HOME_DIR), null);
System.out.println(productConfig.getPrettyVersionString());
return null;
} else if (CommandLineConstants.HELP.equals(arg) || CommandLineConstants.SHORT_HELP.equals(arg) || CommandLineConstants.OLD_HELP.equals(arg)) {
Expand Down Expand Up @@ -254,7 +254,7 @@ public static ServerEnvironment determineEnvironment(String[] args, Properties s
throw ServerMessages.MESSAGES.cannotHaveBothInitialServerConfigAndServerConfig();
}
String hostControllerName = null; // No host controller unless in domain mode.
productConfig = new ProductConfig(Module.getBootModuleLoader(), SecurityActions.getSystemProperty(ServerEnvironment.HOME_DIR));
productConfig = new ProductConfig(Module.getBootModuleLoader(), SecurityActions.getSystemProperty(ServerEnvironment.HOME_DIR), systemProperties);
return new ServerEnvironment(hostControllerName, systemProperties, systemEnvironment, serverConfig, initialServerConfig, launchType, runningMode, productConfig);
}

Expand Down
4 changes: 2 additions & 2 deletions server/src/main/java/org/jboss/as/server/ServerStartTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@
import org.jboss.as.controller.persistence.AbstractConfigurationPersister;
import org.jboss.as.controller.persistence.ConfigurationPersistenceException;
import org.jboss.as.controller.persistence.ExtensibleConfigurationPersister;
import org.jboss.as.server.mgmt.domain.ServerBootOperationsService;
import org.jboss.as.server.mgmt.domain.HostControllerClient;
import org.jboss.as.server.mgmt.domain.HostControllerConnectionService;
import org.jboss.as.server.mgmt.domain.ServerBootOperationsService;
import org.jboss.as.server.parsing.StandaloneXml;
import org.jboss.as.version.ProductConfig;
import org.jboss.dmr.ModelNode;
Expand Down Expand Up @@ -121,7 +121,7 @@ public ServerStartTask(final String hostControllerName, final String serverName,
@Override
public AsyncFuture<ServiceContainer> run(final List<ServiceActivator> runServices) {
final Bootstrap bootstrap = Bootstrap.Factory.newInstance();
final ProductConfig productConfig = new ProductConfig(Module.getBootModuleLoader(), home);
final ProductConfig productConfig = new ProductConfig(Module.getBootModuleLoader(), home, properties);
// Create server environment on the server, so that the system properties are getting initialized on the right side
final ServerEnvironment providedEnvironment = new ServerEnvironment(hostControllerName, properties,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ private static class ModelControllerService extends AbstractControllerService {
properties.put("jboss.home.dir", ".");

final String hostControllerName = "hostControllerName"; // Host Controller name may not be null when in a managed domain
environment = new ServerEnvironment(hostControllerName, properties, new HashMap<String, String>(), null, null, ServerEnvironment.LaunchType.DOMAIN, null, new ProductConfig(Module.getBootModuleLoader(), "."));
environment = new ServerEnvironment(hostControllerName, properties, new HashMap<String, String>(), null, null, ServerEnvironment.LaunchType.DOMAIN, null, new ProductConfig(Module.getBootModuleLoader(), ".", properties));
extensionRegistry = new ExtensionRegistry(ProcessType.STANDALONE_SERVER, new RunningModeControl(RunningMode.NORMAL));
}

Expand Down
37 changes: 36 additions & 1 deletion version/src/main/java/org/jboss/as/version/ProductConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.io.Serializable;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Map;
import java.util.Properties;
import java.util.jar.Manifest;

Expand All @@ -40,11 +41,13 @@
*
*/
public class ProductConfig implements Serializable {
private static final long serialVersionUID = 1L;

private final String name;
private final String version;
private final String consoleSlot;

public ProductConfig(ModuleLoader loader, String home) {
public ProductConfig(ModuleLoader loader, String home, Map<?, ?> providedProperties) {
String productName = null;
String productVersion = null;
String consoleSlot = null;
Expand All @@ -70,6 +73,8 @@ public ProductConfig(ModuleLoader loader, String home) {
consoleSlot = manifest.getMainAttributes().getValue("JBoss-Product-Console-Slot");
}
}

setSystemProperties(props, providedProperties);
} catch (Exception e) {
// Don't care
}
Expand Down Expand Up @@ -127,4 +132,34 @@ public static String getPrettyVersionString(final String name, String version1,
return String.format("JBoss AS %s \"%s\"", version1, version2);
}

private void setSystemProperties(final Properties propConfProps, final Map providedProperties) {
if (propConfProps.size() == 0) {
return;
}

PrivilegedAction<Void> action = new PrivilegedAction<Void>() {
@Override
public Void run() {
for (Map.Entry<Object, Object> entry : propConfProps.entrySet()) {
String key = (String)entry.getKey();
if (!key.equals("slot") && System.getProperty(key) == null) {
//Only set the property if it was not defined by other means
//System properties defined in standalone.xml, domain.xml or host.xml will overwrite
//this as specified in https://issues.jboss.org/browse/AS7-6380

System.setProperty(key, (String)entry.getValue());

//Add it to the provided properties used on reload by the server environment
providedProperties.put(key, entry.getValue());
}
}
return null;
}
};
if (System.getSecurityManager() == null) {
action.run();
} else {
AccessController.doPrivileged(action);
}
}
}

0 comments on commit 968da93

Please sign in to comment.