use of com.google.gerrit.pgm.Daemon in project gerrit by GerritCodeReview.
the class GerritServer method start.
/** Returns fully started Gerrit server */
static GerritServer start(Description desc, Config baseConfig) throws Exception {
Config cfg = desc.buildConfig(baseConfig);
Logger.getLogger("com.google.gerrit").setLevel(Level.DEBUG);
CyclicBarrier serverStarted = new CyclicBarrier(2);
Daemon daemon = new Daemon(() -> {
try {
serverStarted.await();
} catch (InterruptedException | BrokenBarrierException e) {
throw new RuntimeException(e);
}
}, Paths.get(baseConfig.getString("gerrit", null, "tempSiteDir")));
daemon.setEmailModuleForTesting(new FakeEmailSender.Module());
daemon.setEnableSshd(SshMode.useSsh());
final File site;
ExecutorService daemonService = null;
if (desc.memory()) {
site = null;
mergeTestConfig(cfg);
// Set the log4j configuration to an invalid one to prevent system logs
// from getting configured and creating log files.
System.setProperty(SystemLog.LOG4J_CONFIGURATION, "invalidConfiguration");
cfg.setBoolean("httpd", null, "requestLog", false);
cfg.setBoolean("sshd", null, "requestLog", false);
cfg.setBoolean("index", "lucene", "testInmemory", true);
cfg.setString("gitweb", null, "cgi", "");
daemon.setEnableHttpd(desc.httpd());
daemon.setLuceneModule(LuceneIndexModule.singleVersionAllLatest(0));
daemon.setDatabaseForTesting(ImmutableList.<Module>of(new InMemoryTestingDatabaseModule(cfg)));
daemon.start();
} else {
site = initSite(cfg);
daemonService = Executors.newSingleThreadExecutor();
@SuppressWarnings("unused") Future<?> possiblyIgnoredError = daemonService.submit(() -> {
int rc = daemon.main(new String[] { "-d", site.getPath(), "--headless", "--console-log", "--show-stack-trace" });
if (rc != 0) {
System.err.println("Failed to start Gerrit daemon");
serverStarted.reset();
}
return null;
});
serverStarted.await();
System.out.println("Gerrit Server Started");
}
Injector i = createTestInjector(daemon);
return new GerritServer(desc, i, daemon, daemonService);
}
use of com.google.gerrit.pgm.Daemon in project gerrit by GerritCodeReview.
the class GerritGwtDebugLauncher method mainImpl.
private int mainImpl(String[] argv) {
List<String> sdmLauncherOptions = new ArrayList<>();
List<String> daemonLauncherOptions = new ArrayList<>();
// Separator between Daemon and Codeserver parameters is "--"
boolean daemonArgumentSeparator = false;
int i = 0;
for (; i < argv.length; i++) {
if (!argv[i].equals("--")) {
sdmLauncherOptions.add(argv[i]);
} else {
daemonArgumentSeparator = true;
break;
}
}
if (daemonArgumentSeparator) {
++i;
for (; i < argv.length; i++) {
daemonLauncherOptions.add(argv[i]);
}
}
Options options = new Options();
if (!options.parseArgs(sdmLauncherOptions.toArray(new String[sdmLauncherOptions.size()]))) {
log.error("Failed to parse codeserver arguments");
return 1;
}
CodeServer.main(options);
try {
int r = new Daemon().main(daemonLauncherOptions.toArray(new String[daemonLauncherOptions.size()]));
if (r != 0) {
log.error("Daemon exited with return code: " + r);
return 1;
}
} catch (Exception e) {
log.error("Cannot start daemon", e);
return 1;
}
return 0;
}
Aggregations