use of org.wildfly.core.launcher.BootableJarCommandBuilder in project wildfly-core by wildfly.
the class Server method start.
protected void start(PrintStream out) {
try {
CommandBuilder cbuilder = null;
boolean needNormalModeCheck = false;
if (isBootableJar) {
final Path bootableJarPath = Paths.get(bootableJar);
if (Files.notExists(bootableJarPath) || Files.isDirectory(bootableJarPath)) {
throw new IllegalStateException("Cannot find: " + bootableJar);
}
final BootableJarCommandBuilder commandBuilder = BootableJarCommandBuilder.of(bootableJarPath);
commandBuilder.setInstallDir(Paths.get(installDir));
cbuilder = commandBuilder;
commandBuilder.setJavaHome(legacyJavaHome == null ? javaHome : legacyJavaHome);
if (jvmArgs != null) {
commandBuilder.setJavaOptions(jvmArgs.split("\\s+"));
}
if (Boolean.getBoolean(serverDebug)) {
commandBuilder.setDebug(true, serverDebugPort);
}
// we are testing, of course we want assertions and set-up some other defaults
commandBuilder.addJavaOption("-ea").setBindAddressHint("management", managementAddress);
if (jbossArgs != null) {
String[] args = jbossArgs.split("\\s+");
for (String a : args) {
if (a.startsWith("--cli-script=")) {
needNormalModeCheck = true;
break;
}
}
commandBuilder.addServerArguments(args);
}
commandBuilder.addServerArgument("-D[Standalone]");
} else {
final Path jbossHomeDir = Paths.get(jbossHome);
if (Files.notExists(jbossHomeDir) && !Files.isDirectory(jbossHomeDir)) {
throw new IllegalStateException("Cannot find: " + jbossHomeDir);
}
final StandaloneCommandBuilder commandBuilder = StandaloneCommandBuilder.of(jbossHomeDir);
cbuilder = commandBuilder;
if (modulePath != null && !modulePath.isEmpty()) {
commandBuilder.setModuleDirs(modulePath.split(Pattern.quote(File.pathSeparator)));
}
commandBuilder.setJavaHome(legacyJavaHome == null ? javaHome : legacyJavaHome);
if (jvmArgs != null) {
commandBuilder.setJavaOptions(jvmArgs.split("\\s+"));
}
if (Boolean.getBoolean(serverDebug)) {
commandBuilder.setDebug(true, serverDebugPort);
}
if (this.startMode == StartMode.ADMIN_ONLY) {
commandBuilder.setAdminOnly();
} else if (this.startMode == StartMode.SUSPEND) {
commandBuilder.setStartSuspended();
}
if (readOnly) {
commandBuilder.setServerReadOnlyConfiguration(serverConfig);
} else {
commandBuilder.setServerConfiguration(serverConfig);
}
if (gitRepository != null) {
commandBuilder.setGitRepository(gitRepository, gitBranch, gitAuthConfiguration);
}
commandBuilder.setYamlFiles(yamlFiles);
if (configDir != null) {
commandBuilder.addJavaOption("-Djboss.server.config.dir=" + configDir.toString());
}
// we are testing, of course we want assertions and set-up some other defaults
commandBuilder.addJavaOption("-ea").setBindAddressHint("management", managementAddress);
if (jbossArgs != null) {
commandBuilder.addServerArguments(jbossArgs.split("\\s+"));
}
commandBuilder.addServerArgument("-D[Standalone]");
}
StringBuilder builder = new StringBuilder("Starting container with: ");
for (String arg : cbuilder.build()) {
builder.append(arg).append(" ");
}
log.info(builder.toString());
process = Launcher.of(cbuilder).setRedirectErrorStream(true).launch();
new Thread(new ConsoleConsumer(process.getInputStream(), out)).start();
final Process proc = process;
shutdownThread = ProcessHelper.addShutdownHook(proc);
createClient();
long timeout = startupTimeout * 1000;
boolean serverAvailable = false;
long sleep = 1000;
while (timeout > 0 && !serverAvailable) {
long before = System.currentTimeMillis();
serverAvailable = client.isServerInRunningState();
if (serverAvailable && needNormalModeCheck) {
serverAvailable = client.isServerInNormalMode();
}
timeout -= (System.currentTimeMillis() - before);
if (!serverAvailable) {
if (processHasDied(proc))
break;
Thread.sleep(sleep);
timeout -= sleep;
sleep = Math.max(sleep / 2, 100);
}
}
if (!serverAvailable) {
destroyProcess();
throw new RuntimeException("Managed server was not started within " + startupTimeout + " seconds.");
}
} catch (Exception e) {
safeCloseClient();
throw new RuntimeException("Could not start container", e);
}
}
Aggregations