Search:  
Gentoo Wiki

Tomcat_Gentoo_ebuild

Author : Mark Wolfe <mwolfe@netspace.net.au>

Contents

Introduction

Installation of software in gentoo typically divides parts of a third party application into their respective places, based on an established standard. The current tomcat only partially complies with this standard, by installing most of the server to /opt.

Another point to note is the fact that the current ebuild does not use the TOMCAT_BASE option allowing you to seperate runtime data and the actual binary files.

To comply with the normal gentoo file location standards and offer users greater flexibility both of these issues need to be rectified.

This document details a proposed layout for the new tomcat installation as well as describing how to customise tomcat once installed.

Proposed layout

The root directory of a typical tomcat binary distribution is layed out as illustrated in the following listing.

markw@mojo jakarta-tomcat-5.0.28 $ ls -l
total 72
drwxr-xr-x  2 markw users  4096 Oct 18 22:14 bin
drwxr-xr-x  5 markw users  4096 Aug 29 10:02 common
drwxr-xr-x  3 markw users  4096 Aug 29 10:02 conf
drwxr-xr-x  2 markw users  4096 Aug 29 10:02 logs
drwxr-xr-x  5 markw users  4096 Aug 29 10:02 server
drwxr-xr-x  4 markw users  4096 Aug 29 10:02 shared
drwxr-xr-x  2 markw users  4096 Aug 29 10:02 temp
drwxr-xr-x  8 markw users  4096 Aug 29 10:02 webapps
drwxr-xr-x  2 markw users  4096 Aug 29 10:02 work

To fit in with gentoo standards, Tomcat will be disected and installed into the correct locations as follows:

drwxr-xr-x  3 markw users  4096 Aug 29 10:02 conf
drwxr-xr-x  2 markw users  4096 Aug 29 10:02 work
drwxr-xr-x  2 markw users  4096 Aug 29 10:02 temp
drwxr-xr-x  8 markw users  4096 Aug 29 10:02 webapps
drwxr-xr-x  2 markw users  4096 Aug 29 10:02 logs
drwxr-xr-x  2 markw users  4096 Oct 18 22:14 bin
drwxr-xr-x  5 markw users  4096 Aug 29 10:02 common
drwxr-xr-x  5 markw users  4096 Aug 29 10:02 server
drwxr-xr-x  4 markw users  4096 Aug 29 10:02 shared

How these parts will be relocated is explained in the more detail in the following sections.

Configuration Files

In addition to simply moving the /conf directory under /etc, Tomcat will be installed in such a way as to allow for different configuration file profiles. Each profiles configuration files will located in a sub-directory under /etc/tomcat. For example the installation will begin with a profile named default located in /etc/tomcat/default.

In addition to the tomcat configuration files there is the /etc/conf.d/tomcat5 file which contains tomcat variables that are sourced by catalina.sh during execution. These variables are as follows:

Also installed into /etc is the /etc/init.d/tomcat init script.

Web Applications

The initial profile, called default will be installed to /var/lib/tomcat5/default. This profile will contain a group of links as well as the webapps directory which houses the actual J2EE web applications. This directory serves as the hub for the configured profile and is referenced by tomcat as the TOMCAT_BASE.

root@mojo default # ls -l
total 4
lrwxrwxrwx  1 root root   20 Oct 20 22:20 conf -> /etc/tomcat5/default
lrwxrwxrwx  1 root root   24 Oct 20 22:20 logs -> /var/log/tomcat5/default
lrwxrwxrwx  1 root root   24 Oct 20 22:19 temp -> /var/tmp/tomcat5/default
drwxr-xr-x  8 root root 4096 Oct 20 22:19 webapps
lrwxrwxrwx  1 root root   24 Oct 20 22:20 work -> /var/run/tomcat5/default

log/temp/work Files

These directories hold logs, temp, and working files used by tomcat.


Creating a new Profile

The following steps will create a new tomcat profile. The new profile name will be bob.com.au for the purpose of this example.

1. Run the following commands.

# mkdir  /etc/tomcat5/bob.com.au
# cp -r /etc/tomcat5/default/* /etc/tomcat5/bob.com.au
# mkdir /var/lib/tomcat5/bob.com.au
# mkdir /var/run/tomcat5/bob.com.au
# mkdir /var/tmp/tomcat5/bob.com.au
# mkdir /var/log/tomcat5/bob.com.au
# cp -r /var/lib/tomcat5/default/webapps /var/lib/tomcat5/bob.com.au
# ln -s /var/run/tomcat5/bob.com.au /var/lib/tomcat5/bob.com.au/work
# ln -s /var/tmp/tomcat5/bob.com.au /var/lib/tomcat5/bob.com.au/temp
# ln -s /var/log/tomcat5/bob.com.au /var/lib/tomcat5/bob.com.au/logs
# ln -s /etc/tomcat5/bob.com.au /var/lib/tomcat5/bob.com.au/conf

2. Then change PROFILE="default" in the /etc/conf.d/tomcat5 to PROFILE="bob.com.au"


Do it automatically with Scripts

add-tomcat-profile

#!/bin/bash 

TOMCAT_BASE_DIR="tomcat-5"
PROFILE="$1" 

if [ -z $PROFILE ]; then
        echo "usage: add-tomcat-profile PROFILE"
       exit
fi

if [ -d /etc/$TOMCAT_BASE_DIR/.$PROFILE ]; then
   echo "The profile already exists"
   echo "Quitting....."
fi

umask 002 

for i in etc var/lib var/run var/tmp var/log
   do
   if [ ! -d /$i/$TOMCAT_BASE_DIR/$PROFILE ]; then
       echo "Creating dir /$i/$TOMCAT_BASE_DIR/$PROFILE"
       mkdir /$i/$TOMCAT_BASE_DIR/$PROFILE
   fi
done

cp -r /etc/$TOMCAT_BASE_DIR/default/* /etc/$TOMCAT_BASE_DIR/$PROFILE
mkdir /var/lib/$TOMCAT_BASE_DIR/$PROFILE/webapps
cp -r /var/lib/$TOMCAT_BASE_DIR/default/webapps/ROOT /var/lib/$TOMCAT_BASE_DIR/$PROFILE/webapps

ln -s /var/run/$TOMCAT_BASE_DIR/$PROFILE /var/lib/$TOMCAT_BASE_DIR/$PROFILE/work
ln -s /var/tmp/$TOMCAT_BASE_DIR/$PROFILE /var/lib/$TOMCAT_BASE_DIR/$PROFILE/temp
ln -s /var/log/$TOMCAT_BASE_DIR/$PROFILE /var/lib/$TOMCAT_BASE_DIR/$PROFILE/logs
ln -s /etc/$TOMCAT_BASE_DIR/$PROFILE /var/lib/$TOMCAT_BASE_DIR/$PROFILE/conf

for i in etc var/lib var/run var/tmp var/log
    do
   if [ ! -d /$i/$TOMCAT_BASE_DIR/$PROFILE ]; then
       echo "Setting permission  and ownership dir /$i/$TOMCAT_BASE_DIR/$PROFILE"
       chown -R tomcat:wheel /$i/$TOMCAT_BASE_DIR/$PROFILE
       find /$i/$TOMCAT_BASE_DIR/$PROFILE -t d -exec chmod 2775 {} \;
       find /$i/$TOMCAT_BASE_DIR/$PROFILE -t f -exec chmod 664 {} \;
   fi
done

touch /etc/$TOMCAT_BASE_DIR/.$PROFILE

echo "Profile created succesfully"

del-tomcat-profile

#!/bin/bash

TOMCAT_BASE_DIR="tomcat-5"
PROFILE="$1" 

if [ -z $PROFILE ]; then
       echo "usage: add-tomcat-profile PROFILE"
       exit
fi

if [ $PROFILE == "default" ]; then
       echo "I cannot delete the default profile"
       echo "Quitting....."
       exit
fi

if [ ! -f /etc/$TOMCAT_BASE_DIR/.$PROFILE ]; then
          echo "The profile does not exists"
          echo "Quitting....."
          exit
fi

for i in etc var/lib var/run var/tmp var/log
       do
       if [ -d /$i/$TOMCAT_BASE_DIR/$PROFILE ]; then
               echo "Deleting profile in /$i/$TOMCAT_BASE_DIR/$PROFILE"
               rm -r /$i/$TOMCAT_BASE_DIR/$PROFILE
               ls -l /$i/$TOMCAT_BASE_DIR/$PROFILE
       fi
done

echo "Profile deleted"

Future Enhancements

See Also

HOWTO_Apache2_and_Tomcat5

Retrieved from "http://www.gentoo-wiki.info/Tomcat_Gentoo_ebuild"

Last modified: Wed, 11 Jan 2006 07:15:00 +0000 Hits: 13,427