Fix init from WebAppInitializer when using -Dgerrit.site_path
This fix is mostly useful for those developers who want to deploy/test Gerrit in Tomcat, use the embedded H2 database and have automatic init on deployment. The init of a new site on startup (from WebAppInitializer) was failing when the site was provided via the -Dgerrit.site_path property because we assumed that the database initialization has to be skipped always when running in a servlet container. However, this is only true for the case when using the -Dgerrit.init_path. When Gerrit site is provided via -Dgerrit.site_path then we have to perform database initialization. Change-Id: Id577f391cd888bd71ec8502e8ad2f621cbc3fd80
This commit is contained in:
parent
dfc4e932e2
commit
e90d6e81d3
@ -37,6 +37,18 @@ if defined, will be used to determine the site path. The database
|
||||
connectivity, also for this case, is defined by the `jdbc/ReviewDb`
|
||||
JNDI property.
|
||||
|
||||
[WARNING]
|
||||
Defining the `jdbc/ReviewDb` JNDI property for an H2 database under the
|
||||
path defined by either `gerrit.site_path` or `gerrit.init_path` will
|
||||
cause an incomplete auto initialization and Gerrit will fail to start.
|
||||
Opening a connection to such database will create a subfolder under the
|
||||
site path folder (in order to create the H2 database) and Gerrit will
|
||||
not any more consider that site path to be new and, because of that,
|
||||
skip some required initialization steps (for example, Lucene index
|
||||
creation). In order to auto initialize Gerrit with an embedded H2
|
||||
database use the `gerrit.site_path` to define the location of the review
|
||||
site and don't define a JNDI resource with a URL under that path.
|
||||
|
||||
=== Example 1
|
||||
|
||||
Prepare Tomcat so that a site is initialized at a given path using
|
||||
|
@ -57,19 +57,22 @@ import javax.sql.DataSource;
|
||||
public class BaseInit extends SiteProgram {
|
||||
|
||||
private final boolean standalone;
|
||||
private final boolean initDb;
|
||||
|
||||
public BaseInit() {
|
||||
this.standalone = true;
|
||||
this.initDb = true;
|
||||
}
|
||||
|
||||
public BaseInit(File sitePath, boolean standalone) {
|
||||
this(sitePath, null, standalone);
|
||||
public BaseInit(File sitePath, boolean standalone, boolean initDb) {
|
||||
this(sitePath, null, standalone, initDb);
|
||||
}
|
||||
|
||||
public BaseInit(File sitePath, final Provider<DataSource> dsProvider,
|
||||
boolean standalone) {
|
||||
boolean standalone, boolean initDb) {
|
||||
super(sitePath, dsProvider);
|
||||
this.standalone = standalone;
|
||||
this.initDb = initDb;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -148,7 +151,7 @@ public class BaseInit extends SiteProgram {
|
||||
final File sitePath = getSitePath();
|
||||
final List<Module> m = new ArrayList<Module>();
|
||||
|
||||
m.add(new InitModule(standalone));
|
||||
m.add(new InitModule(standalone, initDb));
|
||||
m.add(new AbstractModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
|
@ -63,7 +63,7 @@ public class Init extends BaseInit {
|
||||
}
|
||||
|
||||
public Init(File sitePath) {
|
||||
super(sitePath, true);
|
||||
super(sitePath, true, true);
|
||||
batchMode = true;
|
||||
noAutoStart = true;
|
||||
}
|
||||
|
@ -25,9 +25,11 @@ import java.lang.annotation.Annotation;
|
||||
public class InitModule extends FactoryModule {
|
||||
|
||||
private final boolean standalone;
|
||||
private final boolean initDb;
|
||||
|
||||
public InitModule(boolean standalone) {
|
||||
public InitModule(boolean standalone, boolean initDb) {
|
||||
this.standalone = standalone;
|
||||
this.initDb = initDb;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -43,7 +45,7 @@ public class InitModule extends FactoryModule {
|
||||
step().to(UpgradeFrom2_0_x.class);
|
||||
|
||||
step().to(InitGitManager.class);
|
||||
if (standalone) {
|
||||
if (initDb) {
|
||||
step().to(InitDatabase.class);
|
||||
}
|
||||
step().to(InitIndex.class);
|
||||
|
@ -43,7 +43,7 @@ public final class SiteInitializer {
|
||||
File site = new File(sitePath);
|
||||
LOG.info(String.format("Initializing site at %s",
|
||||
site.getAbsolutePath()));
|
||||
new BaseInit(site, false).run();
|
||||
new BaseInit(site, false, true).run();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -56,7 +56,7 @@ public final class SiteInitializer {
|
||||
if (site != null) {
|
||||
LOG.info(String.format("Initializing site at %s",
|
||||
site.getAbsolutePath()));
|
||||
new BaseInit(site, new ReviewDbDataSourceProvider(), false).run();
|
||||
new BaseInit(site, new ReviewDbDataSourceProvider(), false, false).run();
|
||||
}
|
||||
} finally {
|
||||
conn.close();
|
||||
|
Loading…
x
Reference in New Issue
Block a user