Embed Jetty and run it out of java -jar gerrit.war daemon

We now include Jetty 7.x as part of our distribution WAR and allow
administrators to launch the embedded copy using our Daemon command
line program.  This vastly simplifies server installation as you
do not need to download the Jetty servlet container and configure
it prior to using Gerrit Code Review.

Configuration of Jetty is performed using our gerrit.config, rather
than the Jetty XML configuration language.  Jetty's language can be
quite a bit more powerful for isoteric configurations, but we want
to embed Jetty to simplify setup, not complicate it.  Gerrit's own
configuration file in the git syntax is simpler, so we stick with
that and offer a limited subset of Jetty's configuration features
through httpd.* properties.

Logging currently goes only to stderr, which is fine for toy setups
but probably not ideal for a production environment.

Unfortunately we are still relying on GerritServer.properties to
get us the database connection information, and this DataSource is
not pooled.  Thus the web handlers in our embedded container will
run slightly slower then the web handlers in a standalone container,
as the latter will be likely be using a connection pool configured
out of the container's JNDI namespace.

Bug: issue 202
Change-Id: Ia7956ba48cbc3a8d4241101db5ff493e16d26b9f
Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
Shawn O. Pearce
2009-11-11 14:51:30 -08:00
parent 022e9cce02
commit fa2486a397
21 changed files with 908 additions and 72 deletions

View File

@@ -19,6 +19,7 @@ import static com.google.inject.Stage.PRODUCTION;
import com.google.gerrit.lifecycle.LifecycleManager;
import com.google.gerrit.server.config.CanonicalWebUrlModule;
import com.google.gerrit.server.config.DatabaseModule;
import com.google.gerrit.server.config.GerritConfigModule;
import com.google.gerrit.server.config.GerritGlobalModule;
import com.google.gerrit.server.config.MasterNodeStartup;
import com.google.gerrit.sshd.SshModule;
@@ -47,6 +48,7 @@ public class WebAppInitializer extends GuiceServletContextListener {
LoggerFactory.getLogger(WebAppInitializer.class);
private Injector dbInjector;
private Injector cfgInjector;
private Injector sysInjector;
private Injector webInjector;
private Injector sshInjector;
@@ -75,14 +77,8 @@ public class WebAppInitializer extends GuiceServletContextListener {
throw new CreationException(Collections.singleton(first));
}
sysInjector =
GerritGlobalModule.createInjector(dbInjector,
new CanonicalWebUrlModule() {
@Override
protected Class<? extends Provider<String>> provider() {
return HttpCanonicalWebUrlProvider.class;
}
});
cfgInjector = dbInjector.createChildInjector(new GerritConfigModule());
sysInjector = createSysInjector();
sshInjector = createSshInjector();
webInjector = createWebInjector();
@@ -107,11 +103,23 @@ public class WebAppInitializer extends GuiceServletContextListener {
}
}
private Injector createSysInjector() {
final List<Module> modules = new ArrayList<Module>();
modules.add(cfgInjector.getInstance(GerritGlobalModule.class));
modules.add(new CanonicalWebUrlModule() {
@Override
protected Class<? extends Provider<String>> provider() {
return HttpCanonicalWebUrlProvider.class;
}
});
modules.add(new MasterNodeStartup());
return cfgInjector.createChildInjector(modules);
}
private Injector createSshInjector() {
final List<Module> modules = new ArrayList<Module>();
modules.add(new SshModule());
modules.add(new MasterCommandModule());
modules.add(new MasterNodeStartup());
return sysInjector.createChildInjector(modules);
}

View File

@@ -18,6 +18,8 @@ log4j.appender.stderr.target=System.err
log4j.appender.stderr.layout=org.apache.log4j.PatternLayout
log4j.appender.stderr.layout.ConversionPattern=%d::%-5p: %c %x - %m%n
log4j.logger.com.google.gerrit=INFO
# Silence non-critical messages from MINA SSHD.
#
log4j.logger.org.apache.sshd.common=WARN
@@ -25,6 +27,10 @@ log4j.logger.org.apache.sshd.server=WARN
log4j.logger.org.apache.sshd.common.keyprovider.FileKeyPairProvider=INFO
log4j.logger.com.google.gerrit.server.ssh.GerritServerSession=WARN
# Silence non-critical messages from Jetty.
#
log4j.logger.org.eclipse.jetty=INFO
# Silence non-critical messages from mime-util.
#
log4j.logger.eu.medsea.mimeutil=WARN