Skip to content

Running apache tomcat

Tomasz Grabiec edited this page Dec 23, 2013 · 10 revisions

Preparing tomcat image using a module

OSv has now support for combining modules into an executable image. There are a couple of pre-configured modules available for OSv already. They reside in osv-apps repo, which is currently added as a submodule to osv.git under apps/ directory.

The definition for tomcat module is under apps/tomcat. Module definition has several components:

  • Makefile - is called by OSv's make. It should fetch all the necessary files. Currently it downloads and extracts tomcat bundle from apache site. And applies some basic configuration changes.
  • module.py - holds (java) run configurations.
  • usr.manifest - declares which files should be copied into the image file system

You can adjust the configuration as needed.

Building tomcat image

Modules can be combined during image build. There is a default image configuration which pulls tomcat module, it's under images/tomcat.py in osv.git.

To build the image just run:

make image=tomcat

The image will be in build/release/usr.img

Running

To run it just execute:

sudo scripts/run.py -nv

The -nv options enable networking. sudo is needed to configure network interfaces.

Preparing image manually (the old way)

Prepare the deployment

If you already have one you can skip this step.

Install inside the guest image

You need to put the package under /usr/tomcat in the guest file system. For development you can leverage make process to do so:

  • Append the following line to usr.manifest.template replacing /home/tgrabiec/bin/ with the directory in which your tomcat package is located in the host:
/usr/tomcat/**:/home/tgrabiec/bin/apache-tomcat-7.0.47/**
  • run make. On incremental build you will need to remove build/release/usr.img.d before or it will complain about inability to build dependencies.

If you already have the image, you can start OSv and use scp to copy the package.

Start OSv with tomcat

Save the following script as tomcat-cmd-line.sh. It will be used to build the command line for starting tomcat.

#!/usr/bin/env bash
CATALINA_BASE=/usr/tomcat

CATALINA_HOME=$CATALINA_BASE
CLASSPATH=$CATALINA_HOME/bin/bootstrap.jar

# Logging
LOGGING_CONFIG="-Djava.util.logging.config.file=$CATALINA_BASE/conf/logging.properties"
LOGGING_MANAGER="-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager"
CLASSPATH=$CLASSPATH:$CATALINA_HOME/bin/tomcat-juli.jar

CATALINA_TMPDIR=$CATALINA_BASE/temp

echo "java.so $JAVA_OPTS -cp $CLASSPATH \
       $LOGGING_CONFIG \
       $LOGGING_MANAGER \
       $CATALINA_OPTS \
       -Dcatalina.base=$CATALINA_BASE \
       -Dcatalina.home=$CATALINA_HOME \
       -Djava.io.tmpdir=$CATALINA_TMPDIR \
       org.apache.catalina.startup.Bootstrap start"

You can now start OSv:

sudo scripts/run.py -nv -e "`./tomcat-cmd-line.sh`"
Clone this wiki locally