Dashboard > Encore > ... > The Pas Researcher Pack > I am a developer > How to install the portal for development purposes > Running Tomcat from a shell script Jump To: Tribes | Resources | Collaborations
Log In | Sign Up   View a printable version of the current page.  
Added by Stephen Bannasch, last edited by Rokham Sadeghnezhadfard on Jan 23, 2008  (view change)
Labels: 
(None)

Here's a method for managing Tomcat for PAS-Portal development using Unix shell scripts instead of Eclipse.

This is based on the work that Cynick documented in the How to install the portal for development purposes wiki page - unfortunately it was erased after v2 of that page. I have modified it slightly and re-posted it here.

  1. Download the attached file: mytomcat.sh and put it somewhere on your path
  2. make mytomcat.sh executable: chmod u+x mytomcat.sh
  3. Make all the .sh files in CATALINA_HOME/bin executable: chmod u+x *.sh
  4. Either create CATALINA_BASE, CATALINA_HOME, and JAVA_HOME variables with the proper file paths in a shell startup script (ex: .profle, .bash_profile) or add them to the beginning of the mytomcat.sh script.
  5. Copy the conf directory from the unpacked tomcat distribution to where you've defined your CATALINA_BASE.
  6. Create the following directories under your CATALINA_BASE: logs, temp, webapps, work.

Now you can do the following:

$ mytomcat.sh start



Which should respond with something like this *:

Using CATALINA_BASE:   /Users/stephen/dev/mytomcat
Using CATALINA_HOME:   /Users/stephen/dev/apache-tomcat-5.5.25
Using CATALINA_TMPDIR: /Users/stephen/dev/mytomcat/temp
Using JRE_HOME:       /System/Library/Frameworks/JavaVM.framework/Home



*from a MacOS 10.4.11 system

The default Tomcat install should now be running at: http://127.0.0.1:8080

The mytomcat.sh script supplies the following functions:

  • start: start the tomcat server
  • stop: start the tomcat server in debug mode
  • restart: stop and then start the tomcat server
  • killall: terminate the tomcat processes
  • status: display status information about running tomcat processes

file: mytomcat.sh


#!/bin/sh

# set the environment
JAVA_OPTS=""
CATALINA_OPTS=""

# set TIME OUT values
TIMELIMIT=10
SLEEPTIME=1

# Function to wait until all Tomcat processes are killed
waitForTomcatToDie()
{
PROCESSES=`ps auxwww | grep $HOME | grep 'java' | grep 'tomcat' | grep -v 'grep'`
while [ ! -z "$PROCESSES" ] && [ $SECONDS -lt $TIMELIMIT ] && [ $TIMELIMIT -ne 0 ]; do
echo -n "."
sleep $SLEEPTIME
PROCESSES=`ps auxwww | grep $USER | grep 'java' | grep 'tomcat' | grep -v 'grep'`
done
echo ""
if [ ! -z "$PROCESSES" ]; then
PROCESS_ID=`echo $PROCESSES | awk '{ print $2 }'`
echo "Killing process: $PROCESS_ID"
kill -9 $PROCESS_ID
fi
}

# See how we were called.
case "$1" in
start)
$CATALINA_HOME/bin/startup.sh -Dcatalina.base$CATALINA_BASE
;;
debug)
DEBUG_PORT=10001
export JAVA_OPTS="${JAVA_OPTS} -Xdebug -Xrunjdwp:transport=dt_socket,address{DEBUG_PORT},server=y,suspend=n"
$CATALINA_HOME/bin/startup.sh -Dcatalina.base{CATALINA_BASE}
;;
stop)
$CATALINA_HOME/bin/shutdown.sh
waitForTomcatToDie
;;
restart)
$0 stop
$0 start
;;
killall)
waitForTomcatToDie
;;
status)
PROCESSES=`ps auxwww | grep $USER | grep 'java' | grep 'tomcat' | grep -v 'grep'`
if [ -z "$PROCESSES" ]; then
echo "Tomcat is stopped"
else
PROCESS_ID=`echo $PROCESSES | awk '{ print $2 }'`
echo "Tomcat (pid $PROCESS_ID) is running..."
fi
;;
*)
echo "Usage: $0 {start|debug|stop|restart|killall|status}"
exit 1
esac

exit 0



it doesn't work well for CATALINA_BASE Multiple Tomcat 4 Instances

Posted by Anonymous at May 12, 2008 09:43 | Permalink | Reply To This
Site powered by a free Open Source Project / Non-profit License (more) of Confluence - the Enterprise wiki.
Learn more or evaluate Confluence for your organisation.