Monday, November 06, 2006

OSAF Cosmo calendar server served by Apache and JK Tomcat connector

Hello everyone again !

Today (tonight) I am going to tell you how you can deal with configuring Cosmo calendar server behind Apache.

As you all know Cosmo is promising project developed at Open Source Applications Foundation (OSAF). Because here in Seges we want to take things seriously and our time serious is, we decided to share this information among us with more complex tool. Because there is huge amount of clients and servers around, it is always hard to decide. Java, configurability, accessibility and warm development community were facts that decided.

The real problem was how to enable access to Cosmo server running in Tomcat container through HTTP/HTTPS that all guys in our corporation can access shared calendar. Simple answer - Tomcat JK connector. And then it went smooth (sometimes) :)

OK. Here are the steps:

1. Because we want bleeding edge Cosmo, we build it from source (Cosmo development home). Build process is pretty straightforward, so you checkout sources from SVN repository and run some Maven scripts (build instructions are on their wiki).

Finally it will end with something like maven dist:release in cosmo/snarf/ directory and then you will unpack this distribution into directory where you want to deploy it and have accessible from Apache.

2. Append Tomcat JK connector in <cosmodir>/tomcat/conf/server.xml in this way:
<Server port="8005" shutdown="SHUTDOWN">
<GlobalNamingResources>
<!-- ... other stuff ... -->
<Service name="Catalina">
<Connector port="8080" enableLookups="false" minSpareThreads="4"
maxSpareThreads="50" maxThreads="200"/>
<!-- this definition of AJP Connector is important -->
<Connector port="8009" enableLookups="false" redirectPort="8443"
protocol="AJP/1.3" />

<Engine name="Catalina" defaultHost="localhost">
<!-- ... other stuff ... -->
</Engine>
<!-- ... other stuff ... -->
</Server>


3. Add Tomcat JK module to Apache - this will cause that Apache can proxy your requests to Tomcat. This consists of two actions:

3.1 Copy mod_jk.so to your Apache modules directory.
3.2 Define module loading in Apache configuration:

#Tomcat jk
LoadModule jk_module modules/mod_jk.so

# Where to find workers.properties
JkWorkersFile /etc/httpd/conf/workers.properties
# Where to put jk logs
JkLogFile /var/log/httpd/mod_jk.log
# Set the jk log level [debug/error/info]
JkLogLevel info
# Select the log format
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
# JkOptions indicate to send SSL KEY SIZE,
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
# JkRequestLogFormat set the request format
JkRequestLogFormat "%w %V %T"

There is important file worker.properties which defines paths to Tomcat, Java, Apache logs and "worker" bindings - that means which context to proxy where (more about workers is written on official Tomcat connector pages).

4. Configure Apache as proxy at specific URL and HTTP/S domain (I have defined here both HTTP and HTTPS example configuration sufficient for most cases):

# define HTTP embedding
<virtualhost>
...
JkMount /chandler osaf
JkMount /chandler/* osaf

JkMount /manager/* jkstatus
...
</virtualhost>

# if you are interested in HTTPS connectivity

<virtualhost>
SSLEngine On
SSLCertificateKeyFile /somewhere/server.key
SSLCertificateFile /somewhere/server.crt
ServerAdmin webmaster@localhost

...
JkMount /cosmo osaf
JkMount /cosmo/* osaf

JkMount /manager/* jkstatus
...
</virtualhost>

I have "mounted" jkstatus context of Cosmo, too. You can access it through /manager suffix, but this isn't needed for proper functionality.

5. Finally we will bind it all with defining worker.properties file:

workers.apache_log=/var/log/httpd/
workers.tomcat_home=/opt/osaf/tomcat
workers.java_home=/opt/jdk

worker.list=osaf,jkstatus

worker.jkstatus.type=status

worker.osaf.type=ajp13
worker.osaf.host=localhost
worker.osaf.port=8009


Here we have defined where Apache, Tomcat and logs are residing and bound osafWorker and jkstatus workers with Tomcat through ajp13 protocol. This properties file is quite self-explaining :)

6. Now your only option is to start Cosmo with /opt/osaf/bin/osafsrvctl start directory, then (re)start Apache and enjoy https://your.domain/cosmo ;)

Hope everything will work. Good luck admin-friends.