29 January 2007

Tomcat, at last ...

And now the great moment : enter the big one, Tomcat. With some help from here we will proceed.

To start from somewhere, go to the Tomcat website, copy the url for your prefered version (5.5 at the time of writing) and do the same old wget trick :
wget http://apache.iasi.roedu.net/tomcat/tomcat-5/v5.5.20/bin/apache-tomcat-5.5.20.tar.gz
Be sure to be in the /opt folder, and of course you will replace the example I gave here with your own URL.

Untar :
tar -zxvpf apache-tomcat-5.5.20.tar.gz
and set a symbolic link to the newly created folder
ln -s apache-tomcat-5.5.20 tomcat
Ok for now. Go to /etc/init.d/ and create the file named tomcat. In fact, just copy one already there, for example yum. This will preserve all the file attributes we need.

Edit the file (F4 in MC) and enter the following content :

#! /bin/sh
#
# tomcat Starts tomcat
#
# chkconfig: 2345 98 02
# description: tomcat is a J2EE web application container.
#
export TOMCAT_HOME=/opt/tomcat
export JAVA_HOME=/usr/java/jdk1.5.0_11
[ -f ${TOMCAT_HOME}/bin/startup.sh ] exit 0
[ -f ${TOMCAT_HOME}/bin/shutdown.sh ] exit 0

set -e

case "$1"
in
start)
echo -n "Starting tomcat... "
$TOMCAT_HOME/bin/startup.sh >> /var/log/tomcat 2>&1
echo "started."
;;
stop)
echo -n "Stopping tomcat... "
$TOMCAT_HOME/bin/shutdown.sh >>/var/log/tomcat 2>&1
sleep 1
rm -f $TOMCAT_HOME/logs/*
echo "stopped."
;;
restartforce-reload)
echo -n "Restarting
tomcat... "
$TOMCAT_HOME/bin/shutdown.sh >>/var/log/tomcat 2>&1
sleep 1
$TOMCAT_HOME/bin/startup.sh >>/var/log/tomcat 2>&1
echo "restarted."
;;
*)
N=/etc/init.d/tomcat
echo "Usage: $N
{startstoprestart}" >&2
exit 1
;;
esac

exit 0
Now add tomcat as a service
chkconfig --add tomcat
Start tomcat
service tomcat start
With a little luck you will see
Starting tomcat... started.

Let's test the beast for real :

elinks http://127.0.0.1:8080/

Huraaa !!! It works ! Let's party ...

But wait, don't forget to set the tomcat users. Edit /opt/tomcat/conf/tomcat-users.xml and replace the content with :

<?xml version='1.0' encoding='utf-8'?>
<tomcat-users>
<role rolename="manager">
<role rolename="admin">
<user roles="admin,manager" password="mypwd" username="myuser">
</tomcat-users>

Of course, you will put the username and password you want. This user is the one that have the ability to manage the server trough the WEB admin console. Don't forget to restart Tomcat :

service tomcat restart




No comments:

Post a Comment