Skip to content

Tomcat 6 Installation – Solaris 10 (local zone)

June 7, 2010

Java Installation
* Downloaded & Installed jdk1.6.0_20 (/usr/jdk/jdk1.6.0_20)
* update symlinks /usr/java /usr/jdk/latest

Tomcat Installation
* Downloaded apache-tomcat-6.0.26.tar.gz
* Extract and move to /usr/local
* Symbolic Link apache-tomcat-6.0.26 tomcat6
* Add DB resource jar OJDBC (ojdbc14-10.2.0.4.jar -> /usr/local/tomcat6/lib)
* Configure DB resource /usr/local/tomcat6/conf/server.xml

    <resource name="jdbc/oraLive" auth="Container" type="javax.sql.DataSource" driverclassname="oracle.jdbc.driver.OracleDriver" url="jdbc:oracle:thin:@hostname:port:sid" username="*******" password="*******" removeabandoned="true" removeabandonedtimeout="60" testonborrow="true" validationquery="SELECT SYSDATE FROM DUAL" maxactive="20" maxidle="10" maxwait="10000"></resource>

* Add tomcat managers

 
 <user username="*******" password="*******" roles="manager"></user>

* Create a tomcat user & group (ensure that tomcat has a locked password)

groupadd tomcat
useradd -g tomcat tomcat
chown -R tomcat:tomcat /usr/local/apache-tomcat-6.0.26

Installation & Tomcat Native JNI
* Build, Configure & Install APR: 1.4.2

cd /usr/local/packages/apr-1.4.2
./configure
make
make install

* Compile and install Tomcat Native JNI

 cd /usr/local/packages/tomcat-native-1.1.20-src/jni/native/
 ./configure --with-java-home=/usr/jdk/latest --with-ssl=yes --with-apr=/usr/local/apr --prefix=/usr/local/apache-tomcat-6.0.26
 make
 make install

* Adjust library paths

 crle -l /lib:/usr/lib:/usr/local/apr/lib:/usr/local/tomcat6/lib
 crle -c /var/ld/ld.config -l /lib:/usr/lib:/usr/local/apr/lib:/usr/local/tomcat6/lib

Start Up Script
* /lib/svc/method/svc-tomcat6

#!/sbin/sh
#
# ident "@(#)tomcat6    1.0     10/05/10 SMI"
#

. /lib/svc/share/smf_include.sh

IFCONFIG=`which ifconfig`
AWK=`which awk`
GREP=`which grep`
SED=`which sed`

TOMCAT_USER=tomcat 

CATALINA_HOME=/usr/local/apache-tomcat-6.0.26

JAVA_HOME=/usr/java
CATALINA_PID=$CATALINA_HOME/var/run/tomcat6.pid
TOMCAT_LISTEN_PORT=`$GREP -i "connector port.*http" $CATALINA_HOME/conf/server.xml| $GREP -iv ssl | $AWK '{print $2 }' | $SED 's/["|port=]//g'`
LC_ALL=en_GB.ISO8859-15
IPADDR=`$IFCONFIG -a | $GREP "143\.167" | $AWK '{print $2}'`
JAVA_OPTS=" -server \
        -Xmx2048m \
        -XX:MaxPermSize=1024m  \
        -XX:ReservedCodeCacheSize=256m \
        -Duser.region=GB \
        -Djava.io.tmpdir=$CATALINA_HOME/temp \
        -Dfile.encoding=UTF-8 \
        -Djava.awt.headless=true \
        -Dcom.sun.tools.visualvm.modules.visualgc.originalUI=true \
        -Dcom.sun.management.snmp.port=1161 \
        -Dcom.sun.management.snmp.acl.file=/usr/jdk/latest/jre/lib/management/snmp.acl \
        -Dcom.sun.management.snmp.interface=$IPADDR"
CATALINA_OPTS=" -Dappserver.home=$CATALINA_HOME \
        -Dappserver.base=$CATALINA_HOME \
        -Dcom.sun.management.jmxremote \
        -Dcom.sun.management.jmxremote.port=6080 \
        -Dcom.sun.management.jmxremote.ssl=false \
        -Dcom.sun.management.jmxremote.authenticate=true \
        -Dcom.sun.management.jmxremote.password.file=/usr/java/jre/lib/management/admin.password" 
export CATALINA_PID JAVA_OPTS LC_ALL CATALINA_OPTS CATALINA_HOME JAVA_HOME      

ulimit -n 4096
ARG1=$1
TOMCAT_RUNNING=0
SHUTDOWN_TIMEOUT=2

start()
{
        TOMCAT_RUNNING=0
        echo "Starting Tomcat..."
        if [ -f $CATALINA_PID ]
        then
                echo "Tomcat PID found - already running"
        else
                su  $TOMCAT_USER -c "$CATALINA_HOME/bin/startup.sh 2>&1 > /dev/null"
                #$CATALINA_HOME/bin/startup.sh 
                while [ $TOMCAT_RUNNING -eq 0 ] 
                do
                        running2
                done
        fi
}

stop()
{
        TOMCAT_RUNNING=0
        echo "Stopping Tomcat..."
        # check for PID 
        if [ -f $CATALINA_PID ]
        then
                PID=`cat $CATALINA_PID`
                su $TOMCAT_USER -c "$CATALINA_HOME/bin/shutdown.sh 2>&1 > /dev/null"
                COUNT=0
                while [ `ps -p $PID | grep -c $PID` -gt 0 ] 
                do
                        COUNT=`expr $COUNT + 1`
                        #echo $COUNT
                        if [ $COUNT -gt $SHUTDOWN_TIMEOUT ]
                        then
                                killproc
                        fi
                        sleep 1
                done
                
                if [ -f $CATALINA_PID ]
                then
                        rm $CATALINA_PID
                fi
        else
                # check whether tomcat is running & the PID has been deleted (for some unknown reason - if so kill tomcat)
                running
                if [ $TOMCAT_RUNNING -eq 1 ]
                then
                        echo "killing"
                        killproc
                fi
        fi
}

running()
{
        if [ `netstat -an | $GREP -c $TOMCAT_LISTEN_PORT` -gt 0 ]
        then
                TOMCAT_RUNNING=1                
        else
                TOMCAT_RUNNING=0        
        fi
}

running2()
{
        if [ `tail -5  $CATALINA_HOME/logs/catalina.out  | $GREP -ci "server startup in"` -eq 1 ] 
        then
                TOMCAT_RUNNING=1
        else
                TOMCAT_RUNNING=0
        fi

}

killproc()
{
        #echo "Killing Tomcat..."
        for i in `/usr/ucb/ps -auxwww | $GREP $CATALINA_HOME | egrep -v "grep|ps -auxwww" | $AWK '{print $2}'` 
        do 
                kill -9 $i
        done 
}

case "$1" in
start)
        start
        ;;
restart)
        stop
        sleep 5
        start
        ;;
stop)
        stop
        ;;
*)
        echo "Usage: $0 {start|stop|restart}"
        exit 1
        ;;
esac

SMF Manifest

* Import using svccfg import tomcat6-manifest, tomcat6-manifest:



<service_bundle type="manifest" name="tomcat6:default">
  <service name="application/tomcat6" type="service" version="6">
    <create_default_instance enabled="false"></create_default_instance>
    <single_instance></single_instance>
    <dependency name="network" grouping="require_all" restart_on="none" type="service">
        <service_fmri value="svc:/milestone/network:default"></service_fmri>
    </dependency>
    <dependency name="name-services" grouping="require_all" restart_on="none" type="service">
        <service_fmri value="svc:/milestone/name-services:default"></service_fmri>
    </dependency>
    <exec_method name="start" type="method" exec="/lib/svc/method/svc-tomcat6 %m" timeout_seconds="3600">
      <method_context></method_context>
    </exec_method>
    <exec_method name="stop" type="method" exec="/lib/svc/method/svc-tomcat6 %m" timeout_seconds="3600">
      <method_context></method_context>
    </exec_method>
    <property_group name="startd" type="framework">
      <propval name="ignore_error" type="astring" value="core,signal"></propval>
    </property_group>
    <stability value="Stable"></stability>
    <template>
      <common_name>
        <loctext xml:lang="C">Tomcat6 Application Server</loctext>
      </common_name>
      <documentation>
	<doc_link name="Tomcat6 Documentation" uri="http://tomcat.apache.org/tomcat-6.0-doc/index.html"></doc_link>
      </documentation>
    </template>
  </service>
</service_bundle>

About these ads
2 Comments
  1. Thank you, I’ve recently been looking for information about this subject for ages and yours is the greatest I have discovered so far. But, what about the bottom line? Are you certain in regards to the supply?

  2. Hi Achat, don’t entirely understand your question; what do you mean by supply?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: