Option to start headless Gerrit daemon

Add --headless option to the Daemon which will start Gerrit daemon
without the Web UI front end (headless mode).

This may be useful for running Gerrit server with an alternative (rest
based) UI or when starting Gerrit server for the purpose of automated
REST/SSH based testing.

Currently this option is only supported via the --headless option of the
daemon program. We would need to introduce a config option in order to
support this feature for deployed war mode.

Change-Id: If45d34dadbcc9c807132ca6c5901aba26d094158
Signed-off-by: Sasa Zivkov <sasa.zivkov@sap.com>
This commit is contained in:
Sasa Zivkov 2013-01-30 12:50:28 +01:00
parent f2ed5a5c9b
commit eed56714e0
5 changed files with 60 additions and 6 deletions

View File

@ -0,0 +1,27 @@
// Copyright (C) 2013 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.httpd;
public class GerritUiOptions {
private final boolean headless;
public GerritUiOptions(boolean headless) {
this.headless = headless;
}
public boolean enableDefaultUi() {
return !headless;
}
}

View File

@ -59,9 +59,11 @@ class UrlModule extends ServletModule {
}
private final UrlConfig cfg;
private GerritUiOptions uiOptions;
UrlModule(UrlConfig cfg) {
UrlModule(UrlConfig cfg, GerritUiOptions uiOptions) {
this.cfg = cfg;
this.uiOptions = uiOptions;
}
@Override
@ -69,9 +71,11 @@ class UrlModule extends ServletModule {
filter("/*").through(Key.get(CacheControlFilter.class));
bind(Key.get(CacheControlFilter.class)).in(SINGLETON);
serve("/").with(HostPageServlet.class);
serve("/Gerrit").with(LegacyGerritServlet.class);
serve("/Gerrit/*").with(legacyGerritScreen());
if (uiOptions.enableDefaultUi()) {
serve("/").with(HostPageServlet.class);
serve("/Gerrit").with(LegacyGerritServlet.class);
serve("/Gerrit/*").with(legacyGerritScreen());
}
serve("/cat/*").with(CatServlet.class);
serve("/logout").with(HttpLogoutServlet.class);
serve("/signout").with(HttpLogoutServlet.class);

View File

@ -14,8 +14,8 @@
package com.google.gerrit.httpd;
import static com.google.inject.Scopes.SINGLETON;
import static com.google.gerrit.extensions.registration.PrivateInternals_DynamicTypes.registerInParentInjectors;
import static com.google.inject.Scopes.SINGLETON;
import com.google.gerrit.common.data.GerritConfig;
import com.google.gerrit.extensions.registration.DynamicSet;
@ -43,6 +43,7 @@ import com.google.inject.AbstractModule;
import com.google.inject.Inject;
import com.google.inject.Injector;
import com.google.inject.ProvisionException;
import com.google.inject.name.Named;
import com.google.inject.servlet.RequestScoped;
import com.google.inject.servlet.ServletModule;
@ -55,15 +56,18 @@ public class WebModule extends FactoryModule {
private final UrlModule.UrlConfig urlConfig;
private final boolean wantSSL;
private final GitWebConfig gitWebConfig;
private final GerritUiOptions uiOptions;
@Inject
WebModule(final AuthConfig authConfig,
final UrlModule.UrlConfig urlConfig,
@CanonicalWebUrl @Nullable final String canonicalUrl,
GerritUiOptions uiOptions,
final Injector creatingInjector) {
this.authConfig = authConfig;
this.urlConfig = urlConfig;
this.wantSSL = canonicalUrl != null && canonicalUrl.startsWith("https:");
this.uiOptions = uiOptions;
this.gitWebConfig =
creatingInjector.createChildInjector(new AbstractModule() {
@ -116,7 +120,7 @@ public class WebModule extends FactoryModule {
throw new ProvisionException("Unsupported loginType: " + authConfig.getAuthType());
}
install(new UrlModule(urlConfig));
install(new UrlModule(urlConfig, uiOptions));
install(new UiRpcModule());
install(new GerritRequestModule());
install(new GitOverHttpServlet.Module());

View File

@ -19,6 +19,7 @@ import static com.google.gerrit.server.schema.DataSourceProvider.Context.MULTI_U
import com.google.gerrit.common.ChangeHookRunner;
import com.google.gerrit.httpd.AllRequestFilter;
import com.google.gerrit.httpd.CacheBasedWebSession;
import com.google.gerrit.httpd.GerritUiOptions;
import com.google.gerrit.httpd.GitOverHttpModule;
import com.google.gerrit.httpd.HttpCanonicalWebUrlProvider;
import com.google.gerrit.httpd.RequestContextFilter;
@ -65,10 +66,12 @@ import com.google.gwtorm.jdbc.JdbcSchema;
import com.google.gwtorm.server.OrmException;
import com.google.gwtorm.server.SchemaFactory;
import com.google.gwtorm.server.StatementExecutor;
import com.google.inject.AbstractModule;
import com.google.inject.Inject;
import com.google.inject.Injector;
import com.google.inject.Module;
import com.google.inject.Provider;
import com.google.inject.name.Names;
import org.eclipse.jgit.lib.Config;
import org.kohsuke.args4j.Option;
@ -113,6 +116,9 @@ public class Daemon extends SiteProgram {
@Option(name = "--run-id", usage = "Cookie to store in $site_path/logs/gerrit.run")
private String runId;
@Option(name = "--headless", usage = "Don't start the UI frontend")
private boolean headless;
private final LifecycleManager manager = new LifecycleManager();
private Injector dbInjector;
private Injector cfgInjector;
@ -315,6 +321,12 @@ public class Daemon extends SiteProgram {
if (!slave) {
modules.add(new MasterNodeStartup());
}
modules.add(new AbstractModule() {
@Override
protected void configure() {
bind(GerritUiOptions.class).toInstance(new GerritUiOptions(headless));
}
});
return cfgInjector.createChildInjector(modules);
}

View File

@ -18,6 +18,7 @@ import static com.google.inject.Scopes.SINGLETON;
import static com.google.inject.Stage.PRODUCTION;
import com.google.gerrit.common.ChangeHookRunner;
import com.google.gerrit.httpd.GerritUiOptions;
import com.google.gerrit.httpd.auth.openid.OpenIdModule;
import com.google.gerrit.httpd.plugins.HttpPluginModule;
import com.google.gerrit.lifecycle.LifecycleManager;
@ -241,6 +242,12 @@ public class WebAppInitializer extends GuiceServletContextListener {
});
modules.add(SshKeyCacheImpl.module());
modules.add(new MasterNodeStartup());
modules.add(new AbstractModule() {
@Override
protected void configure() {
bind(GerritUiOptions.class).toInstance(new GerritUiOptions(false));
}
});
return cfgInjector.createChildInjector(modules);
}