Saturday, April 13, 2013

Howto deploy Gerrit and Jenkins on Tomat

First get Tomcat, Gerrit and Jenkins. The preferred way is to use your distribution's package manager. If you don't have access to the root account or require a newer version you can grab the software from the respective project's websites:
wget http://www.nic.funet.fi/pub/mirrors/apache.org/tomcat/tomcat-7/v7.0.39/bin/apache-tomcat-7.0.39.tar.gz
wget http://gerrit.googlecode.com/files/gerrit-2.6-rc0.war
wget http://mirrors.jenkins-ci.org/war-stable/latest/jenkins.war

Unpack tomcat and place the war files in webapps dir:
tar -xf apache-tomcat-7.0.39.tar.gz
cp jenkins.war apache-tomcat-7.0.39/webapps/
cp gerrit-2.6-rc0.war apache-tomcat-7.0.39/webapps/gerrit.war

Setup the gerrit site:
java -jar gerrit-2.6-rc0.war init -d /install_dir/gerrit

*** Gerrit Code Review 2.6-rc0
***

Create '/install_dir/gerrit' [Y/n]?

*** Git Repositories
***

Location of Git repositories   [git]:

*** SQL Database
***

Database server type           [h2]:

*** User Authentication
***

Authentication method          [OPENID/?]: ?
       Supported options are:
         openid
         openid_sso
         http
         http_ldap
         client_ssl_cert_ldap
         ldap
         ldap_bind
         custom_extension
         development_become_any_account
Authentication method          [OPENID/?]: ldap
LDAP server                    [ldap://localhost]: ldap://ldap.server.net
LDAP username                  :
Account BaseDN                 [DC=ldap,DC=server,DC=net]: o=XXX
Group BaseDN                   [o=XXX]:

*** Email Delivery
***

SMTP server hostname           [localhost]:
SMTP server port               [(default)]:
SMTP encryption                [NONE/?]:
SMTP username                  :

*** Container Process
***

Run as                         [ute]:
Java runtime                   [/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre]:
Copy gerrit.war to /install_dir/gerrit/bin/gerrit.war [Y/n]? n

*** SSH Daemon
***

Listen on address              [*]:
Listen on port                 [29418]:

Gerrit Code Review is not shipped with Bouncy Castle Crypto v144
  If available, Gerrit can take advantage of features
  in the library, but will also function without it.
Download and install it now [Y/n]? Y
Downloading http://www.bouncycastle.org/download/bcprov-jdk16-144.jar ... OK
Checksum bcprov-jdk16-144.jar OK
Generating SSH host key ... rsa... dsa... done

*** HTTP Daemon
***

Behind reverse proxy           [y/N]?
Use SSL (https://)             [y/N]?
Listen on address              [*]:
Listen on port                 [8080]: 7003
Canonical URL                  [http://your.host.domain.net:7003/]: http://your.host.domain.net:4000/gerrit/

*** Plugins
***

Prompt to install core plugins [y/N]?

Initialized /install_dir/gerrit

Stop the built-in Gerrit server as tomcat will be used instead:
/install_dir/gerrit/bin/gerrit.sh stop

Now copy the jar files required for gerrit to start on tomcat:
cp gerrit/lib/bcprov-jdk16-144.jar apache-tomcat-7.0.39/lib/
java -jar apache-tomcat-7.0.39/webapps/gerrit.war cat lib/h2-1.3.168.jar >apache-tomcat-7.0.39/lib/h2-1.3.168.jar

Optionally change the ports:
sed -i 's/port="8080"/port="4000"/' apache-tomcat-7.0.39/conf/server.xml
sed -i 's/port="8443"/port="4443"/' apache-tomcat-7.0.39/conf/server.xml
sed -i 's/port="8009"/port="4009"/' apache-tomcat-7.0.39/conf/server.xml
sed -i 's/port="8005"/port="4005"/' apache-tomcat-7.0.39/conf/server.xml

To enable gerrit to access it's H2 database edit context.xml:
vi apache-tomcat-7.0.39/conf/context.xml

<Resource
    name="jdbc/ReviewDb"
    type="javax.sql.DataSource"
    username=""
    driverClassName="org.h2.Driver"
    password=""
    url="jdbc:h2:file:/install_dir/gerrit/db/ReviewDB"
    maxActive="100"
    maxIdle="20"/>
</Context>


Now create a starter script:
vi start.sh

#!/bin/sh
export CATALINA_HOME="/install_dir/apache-tomcat-7.0.39"
export CATALINA_PID="$CATALINA_HOME/tomcat.pid"
export CATALINA_OPTS="-DGERRIT_SITE=/install_dir/gerrit/ -DJENKINS_HOME=/install_dir/jenkins/ -Xmx1024m"
export JAVA_OPTS="-XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabled -XX:PermSize=256m -XX:MaxPermSize=512m"
cd $CATALINA_HOME/bin && ./startup.sh

Finally execute start.sh:
chmod +x start.sh
./start.sh

Now configure Jenkins using it's administration UI:
http://your.host.domain.net:4000/jenkins/
Setup gerrit permissions by logging in:
http://your.host.domain.net:4000/gerrit/

Optionally configure manager access for Tomcat. That's it!

1 comment:

RR said...

Hi I followed most of your instructions to setup up gerrit under tomcat (with mysql). I am able to run it as a standalone app (with mysql+ldap) but it does not run under tomcat. Tomcat shows it as running (i.e. the start button deactivates and the status shows as running) but I am unable to access the page for gerrit. The tomcat logs do not show any errors (initially it did for mysql credentials etc but I fixed all that). Could you give me pointers on what else to look for?