void resetProvidedProperties() { // We're being reloaded, so restore state to where we were right after constructor was executed providedProperties.clear(); copyProperties(primordialProperties, providedProperties); processNameSet = false; }
public ServerEnvironment( final String hostControllerName, final Properties props, final Map<String, String> env, final String serverConfig, final ConfigurationFile.InteractionPolicy configInteractionPolicy, final LaunchType launchType, final RunningMode initialRunningMode, ProductConfig productConfig, long startTime) { assert props != null; this.launchType = launchType; this.standalone = launchType != LaunchType.DOMAIN; this.initialRunningMode = initialRunningMode == null ? RunningMode.NORMAL : initialRunningMode; this.runningModeControl = new RunningModeControl(this.initialRunningMode); this.startTime = startTime; this.hostControllerName = hostControllerName; if (standalone && hostControllerName != null) { throw ServerLogger.ROOT_LOGGER.hostControllerNameNonNullInStandalone(); } if (!standalone && hostControllerName == null) { throw ServerLogger.ROOT_LOGGER.hostControllerNameNullInDomain(); } // Calculate qualified and unqualified host names, default server name, cluster node name configureQualifiedHostName( props.getProperty(QUALIFIED_HOST_NAME), props.getProperty(HOST_NAME), props, env); // Java system-wide extension dirs javaExtDirs = getFilesFromProperty(JAVA_EXT_DIRS, props); if (launchType.equals(LaunchType.SELF_CONTAINED)) { homeDir = new File(WildFlySecurityManager.getPropertyPrivileged("user.dir", ".")); serverBaseDir = new File(WildFlySecurityManager.getPropertyPrivileged("user.dir", ".")); serverLogDir = new File(WildFlySecurityManager.getPropertyPrivileged("user.dir", ".")); try { File tmpDir = File.createTempFile("wildfly-self-contained", ".d"); if (tmpDir.exists()) { for (int i = 0; i < 10; ++i) { if (tmpDir.exists()) { if (deleteRecursively(tmpDir)) { break; } try { Thread.sleep(100); } catch (InterruptedException e) { break; } } } if (tmpDir.exists()) { throw ServerLogger.ROOT_LOGGER.unableToCreateSelfContainedDir(); } } tmpDir.mkdirs(); tmpDir.deleteOnExit(); serverTempDir = tmpDir; } catch (IOException e) { throw new RuntimeException(e); } serverDataDir = serverTempDir; modulesDir = null; serverConfigurationDir = null; serverConfigurationFile = null; controllerTempDir = null; domainBaseDir = null; domainConfigurationDir = null; WildFlySecurityManager.setPropertyPrivileged( ServerEnvironment.JBOSS_PERSIST_SERVER_CONFIG, "false"); } else { // Must have HOME_DIR homeDir = getFileFromProperty(HOME_DIR, props); if (homeDir == null) { throw ServerLogger.ROOT_LOGGER.missingHomeDirConfiguration(HOME_DIR); } if (!homeDir.exists() || !homeDir.isDirectory()) { throw ServerLogger.ROOT_LOGGER.homeDirectoryDoesNotExist(homeDir); } @SuppressWarnings("deprecation") File tmp = getFileFromProperty(MODULES_DIR, props); if (tmp == null) { tmp = new File(homeDir, "modules"); } else if (!tmp.exists() || !tmp.isDirectory()) { throw ServerLogger.ROOT_LOGGER.modulesDirectoryDoesNotExist(tmp); } modulesDir = tmp; configureBundlesDir(props.getProperty(BUNDLES_DIR), props); tmp = getFileFromProperty(SERVER_BASE_DIR, props); if (tmp == null) { tmp = new File(homeDir, standalone ? "standalone" : "domain/servers/" + serverName); } if (standalone) { if (!tmp.exists()) { throw ServerLogger.ROOT_LOGGER.serverBaseDirectoryDoesNotExist(tmp); } else if (!tmp.isDirectory()) { throw ServerLogger.ROOT_LOGGER.serverBaseDirectoryIsNotADirectory(tmp); } } else { if (tmp.exists()) { if (!tmp.isDirectory()) { throw ServerLogger.ROOT_LOGGER.serverBaseDirectoryIsNotADirectory(tmp); } } else if (!tmp.mkdirs()) { throw ServerLogger.ROOT_LOGGER.couldNotCreateServerBaseDirectory(tmp); } } serverBaseDir = tmp; tmp = getFileFromProperty(SERVER_CONFIG_DIR, props); if (tmp == null) { tmp = new File(serverBaseDir, "configuration"); } serverConfigurationDir = tmp; if (standalone && (!serverConfigurationDir.exists() || !serverConfigurationDir.isDirectory())) { throw ServerLogger.ROOT_LOGGER.configDirectoryDoesNotExist(serverConfigurationDir); } String defaultServerConfig = WildFlySecurityManager.getPropertyPrivileged( JBOSS_SERVER_DEFAULT_CONFIG, "standalone.xml"); serverConfigurationFile = standalone ? new ConfigurationFile( serverConfigurationDir, defaultServerConfig, serverConfig, configInteractionPolicy) : null; // Adds a system property to indicate whether or not the server configuration should be // persisted @SuppressWarnings("deprecation") final String propertyKey = JBOSS_PERSIST_SERVER_CONFIG; WildFlySecurityManager.setPropertyPrivileged( propertyKey, Boolean.toString( configInteractionPolicy == null || !configInteractionPolicy.isReadOnly())); tmp = getFileFromProperty(SERVER_DATA_DIR, props); if (tmp == null) { tmp = new File(serverBaseDir, "data"); } serverDataDir = tmp; if (serverDataDir.exists()) { if (!serverDataDir.isDirectory()) { throw ServerLogger.ROOT_LOGGER.serverDataDirectoryIsNotDirectory(serverDataDir); } } else { if (!serverDataDir.mkdirs()) { throw ServerLogger.ROOT_LOGGER.couldNotCreateServerDataDirectory(serverDataDir); } } tmp = getFileFromProperty(SERVER_CONTENT_DIR, props); if (tmp == null) { @SuppressWarnings("deprecation") String deprecatedProp = SERVER_DEPLOY_DIR; tmp = getFileFromProperty(deprecatedProp, props); } if (tmp == null) { tmp = new File(serverDataDir, "content"); } serverContentDir = tmp; if (serverContentDir.exists()) { if (!serverContentDir.isDirectory()) { throw ServerLogger.ROOT_LOGGER.serverContentDirectoryIsNotDirectory(serverContentDir); } } else if (!serverContentDir.mkdirs()) { throw ServerLogger.ROOT_LOGGER.couldNotCreateServerContentDirectory(serverContentDir); } tmp = getFileFromProperty(SERVER_LOG_DIR, props); if (tmp == null) { tmp = new File(serverBaseDir, "log"); } if (tmp.exists()) { if (!tmp.isDirectory()) { throw ServerLogger.ROOT_LOGGER.logDirectoryIsNotADirectory(tmp); } } else if (!tmp.mkdirs()) { throw ServerLogger.ROOT_LOGGER.couldNotCreateLogDirectory(tmp); } serverLogDir = tmp; tmp = configureServerTempDir(props.getProperty(SERVER_TEMP_DIR), props); if (tmp.exists()) { if (!tmp.isDirectory()) { throw ServerLogger.ROOT_LOGGER.serverTempDirectoryIsNotADirectory(tmp); } } else if (!tmp.mkdirs()) { throw ServerLogger.ROOT_LOGGER.couldNotCreateServerTempDirectory(tmp); } tmp = getFileFromProperty(CONTROLLER_TEMP_DIR, props); if (tmp == null) { tmp = serverTempDir; } if (tmp.exists()) { if (!tmp.isDirectory()) { throw ServerLogger.ROOT_LOGGER.controllerTempDirectoryIsNotADirectory(tmp); } } else if (!tmp.mkdirs()) { throw ServerLogger.ROOT_LOGGER.couldNotCreateControllerTempDirectory(tmp); } controllerTempDir = tmp; // Optional paths for the domain mode tmp = getFileFromProperty(DOMAIN_BASE_DIR, props); if (tmp != null) { if (!tmp.exists() || !tmp.isDirectory()) { throw ServerLogger.ROOT_LOGGER.domainBaseDirDoesNotExist(tmp); } this.domainBaseDir = tmp; } else { this.domainBaseDir = null; } tmp = getFileFromProperty(DOMAIN_CONFIG_DIR, props); if (tmp != null) { if (!tmp.exists() || !tmp.isDirectory()) { throw ServerLogger.ROOT_LOGGER.domainConfigDirDoesNotExist(tmp); } this.domainConfigurationDir = tmp; } else { this.domainConfigurationDir = null; } } boolean allowExecutor = true; String maxThreads = WildFlySecurityManager.getPropertyPrivileged(BOOTSTRAP_MAX_THREADS, null); if (maxThreads != null && maxThreads.length() > 0) { try { Integer.decode(maxThreads); // Property was set to a valid value; user wishes to control core service threads allowExecutor = false; } catch (NumberFormatException ex) { ServerLogger.ROOT_LOGGER.failedToParseCommandLineInteger(BOOTSTRAP_MAX_THREADS, maxThreads); } } allowModelControllerExecutor = allowExecutor; final Path filePath = this.serverDataDir.toPath().resolve(KERNEL_DIR).resolve(UUID_FILE); UUID uuid = null; try { uuid = obtainProcessUUID(filePath); } catch (IOException ex) { throw ServerLogger.ROOT_LOGGER.couldNotObtainServerUuidFile(ex, filePath); } this.serverUUID = uuid; this.productConfig = productConfig; // Keep a copy of the original properties this.primordialProperties = new Properties(); copyProperties(props, primordialProperties); // Create a separate copy for tracking later changes this.providedProperties = new Properties(); copyProperties(primordialProperties, providedProperties); // Provide standard system properties for environment items WildFlySecurityManager.setPropertyPrivileged(QUALIFIED_HOST_NAME, qualifiedHostName); WildFlySecurityManager.setPropertyPrivileged(HOST_NAME, hostName); WildFlySecurityManager.setPropertyPrivileged(SERVER_NAME, serverName); WildFlySecurityManager.setPropertyPrivileged(NODE_NAME, nodeName); setPathProperty(HOME_DIR, homeDir); setPathProperty(MODULES_DIR, modulesDir); setPathProperty(SERVER_BASE_DIR, serverBaseDir); setPathProperty(SERVER_CONFIG_DIR, serverConfigurationDir); setPathProperty(SERVER_DATA_DIR, serverDataDir); setPathProperty(SERVER_DEPLOY_DIR, serverContentDir); setPathProperty(SERVER_LOG_DIR, serverLogDir); setPathProperty(SERVER_TEMP_DIR, serverTempDir); if (launchType.getProcessType() == ProcessType.DOMAIN_SERVER) { if (domainBaseDir != null) { WildFlySecurityManager.setPropertyPrivileged( DOMAIN_BASE_DIR, domainBaseDir.getAbsolutePath()); } if (domainConfigurationDir != null) { WildFlySecurityManager.setPropertyPrivileged( DOMAIN_CONFIG_DIR, domainConfigurationDir.getAbsolutePath()); } } // Register the vfs module as URLStreamHandlerFactory try { ModuleLoader bootLoader = Module.getBootModuleLoader(); Module vfsModule = bootLoader.loadModule(ModuleIdentifier.create(VFS_MODULE_IDENTIFIER)); Module.registerURLStreamHandlerFactoryModule(vfsModule); } catch (Exception ex) { ServerLogger.ROOT_LOGGER.cannotAddURLStreamHandlerFactory(ex, VFS_MODULE_IDENTIFIER); } }