Search in sources :

Example 1 with Daemon

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);
}
Also used : BrokenBarrierException(java.util.concurrent.BrokenBarrierException) Config(org.eclipse.jgit.lib.Config) GerritServerConfig(com.google.gerrit.server.config.GerritServerConfig) FakeEmailSender(com.google.gerrit.testutil.FakeEmailSender) CyclicBarrier(java.util.concurrent.CyclicBarrier) Daemon(com.google.gerrit.pgm.Daemon) Injector(com.google.inject.Injector) ExecutorService(java.util.concurrent.ExecutorService) File(java.io.File)

Example 2 with Daemon

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;
}
Also used : Options(com.google.gwt.dev.codeserver.Options) Daemon(com.google.gerrit.pgm.Daemon) ArrayList(java.util.ArrayList)

Aggregations

Daemon (com.google.gerrit.pgm.Daemon)2 GerritServerConfig (com.google.gerrit.server.config.GerritServerConfig)1 FakeEmailSender (com.google.gerrit.testutil.FakeEmailSender)1 Options (com.google.gwt.dev.codeserver.Options)1 Injector (com.google.inject.Injector)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 BrokenBarrierException (java.util.concurrent.BrokenBarrierException)1 CyclicBarrier (java.util.concurrent.CyclicBarrier)1 ExecutorService (java.util.concurrent.ExecutorService)1 Config (org.eclipse.jgit.lib.Config)1