Issue 2222: Exception thrown during installation
Status:  New
Owner: ----
Reported by rco...@gmail.com, Oct 30, 2013
************************************************************
***** NOTE: THIS BUG TRACKER IS FOR GERRIT CODE REVIEW *****
***** DO NOT SUBMIT BUGS FOR CHROME, ANDROID, INTERNAL *****
***** ISSUES WITH YOUR COMPANY'S GERRIT SETUP, ETC.    *****
***** THOSE ISSUE BELONG IN DIFFERENT ISSUE TRACKERS!  *****
************************************************************

Affected Version: gerrit-2.7 on Redhat 6.4

What steps will reproduce the problem?
1. # java -jar gerrit-2.7.war init -d /srv/git/gerrit
2. answer installer questions
3. wait for installation to complete

What is the expected output? What do you see instead?
Expected the installation to complete successfully.

Saw this:
*** Plugins
*** 

Prompt to install core plugins [y/N]? 

Exception in thread "main" com.google.gwtorm.server.OrmException: Cannot initialize schema
	at com.google.gerrit.server.schema.SchemaUpdater.update(SchemaUpdater.java:57)
	at com.google.gerrit.pgm.Init$SiteRun.upgradeSchema(Init.java:175)
	at com.google.gerrit.pgm.Init.run(Init.java:78)
	at com.google.gerrit.pgm.util.AbstractProgram.main(AbstractProgram.java:67)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at com.google.gerrit.launcher.GerritLauncher.invokeProgram(GerritLauncher.java:168)
	at com.google.gerrit.launcher.GerritLauncher.mainImpl(GerritLauncher.java:92)
	at com.google.gerrit.launcher.GerritLauncher.main(GerritLauncher.java:50)
	at Main.main(Main.java:25)
Caused by: java.io.IOException: Permission denied
	at java.io.UnixFileSystem.createFileExclusively(Native Method)
	at java.io.File.createNewFile(File.java:1006)
	at java.io.File.createTempFile(File.java:1981)
	at org.eclipse.jgit.internal.storage.file.ObjectDirectoryInserter.newTempFile(ObjectDirectoryInserter.java:227)
	at org.eclipse.jgit.internal.storage.file.ObjectDirectoryInserter.toTemp(ObjectDirectoryInserter.java:193)
	at org.eclipse.jgit.internal.storage.file.ObjectDirectoryInserter.insert(ObjectDirectoryInserter.java:90)
	at org.eclipse.jgit.lib.ObjectInserter.insert(ObjectInserter.java:329)
	at com.google.gerrit.server.git.VersionedMetaData.saveFile(VersionedMetaData.java:419)
	at com.google.gerrit.server.git.VersionedMetaData.saveUTF8(VersionedMetaData.java:413)
	at com.google.gerrit.server.git.VersionedMetaData.saveConfig(VersionedMetaData.java:409)
	at com.google.gerrit.server.git.ProjectConfig.onSave(ProjectConfig.java:731)
	at com.google.gerrit.server.git.VersionedMetaData$1.doSave(VersionedMetaData.java:218)
	at com.google.gerrit.server.git.VersionedMetaData$1.write(VersionedMetaData.java:231)
	at com.google.gerrit.server.git.VersionedMetaData$1.write(VersionedMetaData.java:207)
	at com.google.gerrit.server.git.VersionedMetaData.commit(VersionedMetaData.java:157)
	at com.google.gerrit.server.schema.AllProjectsCreator.initAllProjects(AllProjectsCreator.java:174)
	at com.google.gerrit.server.schema.AllProjectsCreator.create(AllProjectsCreator.java:93)
	at com.google.gerrit.server.schema.SchemaCreator.create(SchemaCreator.java:92)
	at com.google.gerrit.server.schema.SchemaUpdater.update(SchemaUpdater.java:55)
	... 11 more

At this point, there were no log files present in the logs/ directory.

Please provide any additional information below.
This was a clean install using a new database.

I checked the database and the schema is there, all 23 tables.  The tables that govern gerrit seem to be populated and gerrit was able to be started using # service gerrit start.  Gerrit started and the web interface responded but on attempting to authenticate, was given this message: 
"Authentication unavailable at this time."

After the authentication step, teh log file now has this stacktrace:
...
[2013-10-30 12:19:26,766] INFO  org.eclipse.jetty.server.handler.ContextHandler : started o.e.j.s.ServletContextHandler{/gerrit,file:/srv/git/gerrit/tmp/gerrit_1336831503204098985_app/gerrit_war/}
[2013-10-30 12:19:26,989] INFO  org.eclipse.jetty.server.AbstractConnector : Started SelectChannelConnector@127.0.0.1:8081
[2013-10-30 12:19:26,990] INFO  com.google.gerrit.pgm.Daemon : Gerrit Code Review 2.7 ready
[2013-10-30 12:19:47,357] ERROR com.google.gerrit.httpd.auth.ldap.LdapLoginServlet : LDAP authentication failed
java.util.NoSuchElementException
        at java.util.ArrayList$Itr.next(ArrayList.java:834)
        at com.google.gerrit.server.account.AccountManager.create(AccountManager.java:294)
        at com.google.gerrit.server.account.AccountManager.authenticate(AccountManager.java:115)
        at com.google.gerrit.httpd.auth.ldap.LdapLoginServlet.doPost(LdapLoginServlet.java:129)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

At this point, I issued a # service gerrit restart and now was able to log in and see all my projects.  However, my user account was not correctly set up.  I had configured gerrit to use LDAP auth and the group information was not used by gerrit to give my account administrator privileges.  See https://code.google.com/p/gerrit/issues/detail?id=2218 for a full description of this problem.

Oct 30, 2013
Project Member #1 bklarson@gmail.com
> Caused by: java.io.IOException: Permission denied

Did the user you used to install Gerrit have write permissions in the target directory?
Oct 30, 2013
#2 rco...@gmail.com
Yes.  First thing I checked but it's the same user account I've used every time.

[gerrit2@uniform ~]$ groups gerrit2
gerrit2 : gerrit2 developers

[gerrit2@uniform ~]$ ls -l /srv/git
total 8
drwxrwxr-x. 11 gerrit2 gerrit2    4096 Oct 30 11:53 gerrit
drwxrwxr-x. 12 git     developers 4096 Oct 25 11:14 projects

Oct 30, 2013
#3 rco...@gmail.com
I purged the tables and sequences from the database and ran the init phase again.  Got the same error about schema initialization abd verified the schema was installed.  However, there was this in the pg_log:
ERROR:  relation "schema_version" does not exist at character 39
STATEMENT:  SELECT T.version_nbr,T.singleton FROM schema_version T WHERE T.singleton=$1

Oct 30, 2013
#4 rco...@gmail.com
This is the content of the schema_version table:

79;"X"
Oct 30, 2013
#5 rco...@gmail.com
I've re-run the installer several times, changing from postgresql to h2, but always get the same stacktrace.  I've purged the gerrit install directory every time and looked for locks but can't find any.  There's no indication in the stacktrace where the temp file is being created but I assume that it's /tmp, which is the default for java on linux.  Can that be confirmed?
Oct 30, 2013
#6 rco...@gmail.com
I made it work by installing as root.  I recursively re-set the permissions to be owned by the gerrit user.  So, there must be a file being written outside of the gerrit target directory.  Is there any reason the documentation says to install it as the gerrit user, as opposed to running as root and having the installer re-set permissions?

And, after all this, I still have the same problem of not being able to access my LDAP groups.
Apr 7, 2014
#7 mitis2...@gmail.com
Had the same issue. I tried to clean a test config and reinit, but failed the same way. The problem was that i forgot to clean the settings in the git folder (which is outside of the gerrit one) and they were originaly created by root. After also cleaning this, the init went smoothly as user gerrit