Wednesday, October 16, 2013

Gerrit configuration on apache tomcat in linux



Download the latest gerrit.war from http://gerrit-releases.storage.googleapis.com/index.html and
deploy it in tomcat as follows

Deploying gerrit war directly in tomcat won't work and need several config modification before up
and running on tomcat.

The tomcat we use is running on 8085 which was created using steps in previous blog( http://balajipraba.blogspot.com/2013/10/creating-custom-tomcat-systemcrtl-daemon.html )

1) First modify tomcat context.xml located in /usr/share/tomcat/

Add the following lines in tag
name="jdbc/ReviewDB"
type="javax.sql.DataSource"
driverClassName="com.mysql.jdbc.Driver"
username="gerrit2"
password="xxxxx"
url="jdbc:mysql://localhost:3306/ReviewDB?autoReconnect=true"
auth="Container"
/>

Don't forget to add double quotes around password

2) Create account in mysql as follows,

CREATE USER 'gerrit2'@'localhost' IDENTIFIED BY 'xxxxxxx';
CREATE DATABASE ReviewDB;
ALTER DATABASE ReviewDB charset=latin1;
GRANT ALL ON ReviewDB.* TO 'gerrit2'@'localhost';
FLUSH PRIVILEGES;

3) Increase 524xxx size in Tomcat manager/WEB-INF/web.xml and also increase java memory size.

4) Configure the gerrit.config file as follows,

[gerrit]
basePath = /[path_git_folder]/All-Projects.git/.git
canonicalWebUrl = http://server:8085/gerrit/

[database]
type = mysql
hostname = localhost
database = ReviewDB
username = gerrit2

[auth]
type = LDAP

[ldap]
server = ldap://server.ch1.com
username = CN=Directory Manager
password = "xxxxxxxx"
accountBase = DC=ch2,DC=com
accountScope = subtree
groupBase = DC=ch,DC=com
accountFullName = DirectoryManager
sslVerify = false
referral = follow

[sendemail]
smtpServer = localhost

[container]
user = gerrit2
javaHome = /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.19.x86_64/jre

[sshd]
listenAddress = *:29418

[httpd]
listenUrl = http://*:8085/

[cache]
directory = cache

Select Y if promted for plugin installation

Note:
i) In basePath variable you should give the absolute path ie. Upto .git folder otherwise you will
get errors like invalid counter etc...
ii) If you use LDAP for authentication then you must give the password of the bind account ex:
Directory Manager in double quotes otherwise gerrit won't accept the password

Now deploy the gerrit.war in tomcat and it should be up and running at http://server:8085/gerrit and don't forget to open the port on firewall for network access.


Creating custom tomcat systemcrtl daemon


This post will guide you to create new systemctrl daemon for apache tomcat which replaces service concept in older linux box.

Running Tomcat instance on different port other than default 8080:

If the port 8080 is not available or some security reasons we can change default port to other port
or better create a new instance of tomcat on another port by follow below steps.

Copy existing tomcat.service(usr/lib/systemd|systemctrl) to new service file ex: cus_tomcat.service and modify as below
# Systemd unit file for customized tomcat
#
# To create clones of this service:
# 1) By default SERVICE_NAME=tomcat. When cloned, the value must be defined
# before tomcat-sysd is called.
# 2) Create /etc/sysconfig/${SERVICE_NAME} from /etc/sysconfig/tomcat
# to override tomcat defaults
[Unit]
Description=Apache Tomcat Web Application Container
After=syslog.target network.target
[Service]
Type=forking
ExecStart=/usr/sbin/cus_tomcat-sysd start
ExecStop=/usr/sbin/cus_tomcat-sysd stop
SuccessExitStatus=143
User=tomcat
Group=tomcat
[Install]
WantedBy=multi-user.target

Copy the original configuration from  /usr/sbin/tomcat-sysd,  /etc/sysconfig/tomcat and paste it in /usr/sbin/cus_tomcat-sysd and /etc/sysconfig/cus_tomcat and modify location of tomcat files as necessary.

Our tomcat is located in /opt/tomcat, Modify the new tomcat conf/server.xml file with new port such that it should not conflict with existing services here it's 8085.

connectionTimeout="20000"
redirectPort="8443" />

<!--
port="8085" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
~

Enable the service
systemctrl enable cus_tomcat.service

Start the service
systemctrl start cus_tomcat.service.

Configuring Icescrum on Apache tomcat in linux

This post will guide you on configuring the Icescrum on apache tomcat in linux and based on official guide.


Downloading the latest icescrum war from http://www.icescrum.org/en/download-en/ and deploying it directly on apache tomcat won't work without tweaking and few configuration changes.

The following configuration was tested on Tomcat 7 with Mysql in Fedora 18 and sure will work on all linux distros.

Add prodDba.properties file in tomcat folder(/usr/share/tomcat/) with below contents


#HSQL Database Engine 1.8.0.10
#Tue Sep 10 10:15:24 IST 2013
hsqldb.script_format=0
runtime.gc_interval=0
sql.enforce_strict_size=false
hsqldb.cache_size_scale=8
readonly=false
hsqldb.nio_data_file=true
hsqldb.cache_scale=14
version=1.8.0
hsqldb.default_table_type=memory
hsqldb.cache_file_scale=1
hsqldb.log_size=200
modified=no
hsqldb.cache_version=1.7.0
hsqldb.original_version=1.8.0
hsqldb.compatible_version=1.8.0

Add /usr/share/tomcat/conf/config.groovy file with following contents

icescrum.project.import.enable = true
icescrum.project.export.enable = true
icescrum.project.creation.enable = true
icescrum.project.private.enable = true
icescrum.gravatar.secure = false
icescrum.gravatar.enable = false
icescrum.registration.enable = true
icescrum.login.retrieve.enable = true
icescrum.auto_follow_productowner = true
icescrum.auto_follow_stakeholder = true
icescrum.auto_follow_scrummaster = true
icescrum.alerts.errors.to = "admin@server"
icescrum.alerts.subject_prefix = "[icescrum]"
icescrum.alerts.enable = true
icescrum.alerts.default.from = "webmaster@icescrum.org"
icescrum.attachments.enable = true
grails.serverURL = "http://appserver:8080/icescrum"
/* Changing the port will require to change
it in the Tomcat server.xml Connector*/
icescrum.debug.enable = false
icescrum.securitydebug.enable = false
icescrum.baseDir = "/usr/share/tomcat/icescrum"
dataSource.driverClassName = "com.mysql.jdbc.Driver"
dataSource.dialect = "org.hibernate.dialect.MySQL5InnoDBDialect"
dataSource.url = "jdbc:mysql://localhost:3306/icescrum?useUnicode=true&characterEncoding=utf8"
dataSource.username = "root"
dataSource.password = "xxx"

Edit /etc/icescrum/config.properties with below contents

dataSource.driverClassName=com.mysql.jdbc.Driver
dataSource.dialect=org.hibernate.dialect.MySQLInnoDBDialect
dataSource.url=jdbc:mysql://localhost:3306/icescrum?
useUnicode=true&characterEncoding=utf8&autoReconnect=true
dataSource.username=root
dataSource.password= ”xxx”
dataSource.dbCreate=update
#grails.mail.host = mail.localhost.com
#grails.mail.port = 25
#grails.mail.username = scrum@icescrum.com
#grails.mail.password =
#icescrum.login.retrieve.enable = true
#serverURL Absolute link required with context name like : http://localhost:8080/icescrum
grails.serverURL=http://appserver:8080/icescrum

Now the icescrum should up and running.

Note:
Modify the grails URL from localhost to FQDN in order to access icescrum from network.

I hope this will solve the problem in deploying Icescrum on Tomcat.