#!/bin/sh # run-tomcat [start|stop|restart|graceful] # d.gilbert, simplified tomcat/bin/catalina.sh to run on flybase servers # feb03 test # # ----------------------------------------------------------------------------- # Start/Stop Script for the CATALINA Server # # Environment Variable Prequisites # # JAVA_HOME Must point at your Java Development Kit installation. # TOMCAT_HOME May point at your Catalina "build" directory. # or this script must exist in $TOMCAT_HOME/bin/ folder # # FIXME: for local configs: # $CATALINA_BASE/conf/catalina.policy # override $CATALINA_BASE/conf/server.xml with "-config mypath/server.xml" # web.xml is hard coded in org/apache/catalina/startup/Constants.java # "catalina.base" / DefaultWebXml = "conf/web.xml"; # # ----------------------------------------------------------------------------- TOMCAT_HOME="/bio/biodb/common/servers/tomcat" ; export TOMCAT_HOME runconf="install.conf" #------------------ # dgg, copied from setclasspath.sh set_classpath() { if [ -z "$JAVA_HOME" ]; then echo "The JAVA_HOME environment variable is not defined" echo "It should point to a Java 1.4 runtime folder with bin/java program" exit 1 fi if [ ! -r "$JAVA_HOME"/bin/java ]; then echo "The JAVA_HOME environment variable is not defined correctly" echo "$JAVA_HOME/bin/java is missing " exit 1 fi if [ -z "$TOMCAT_HOME" ]; then echo "The TOMCAT_HOME environment variable is not defined" echo "This environment variable is needed to run this program" exit 1 fi if [ ! -r "$TOMCAT_HOME"/bin/bootstrap.jar ]; then echo "The TOMCAT_HOME environment variable is not defined correctly" echo "$TOMCAT_HOME/bin/bootstrap.jar is missing " exit 1 fi # Set the default -Djava.endorsed.dirs argument JAVA_ENDORSED_DIRS="$TOMCAT_HOME"/bin:"$TOMCAT_HOME"/common/endorsed # Set standard CLASSPATH CLASSPATH="$JAVA_HOME"/lib/tools.jar # Set standard commands for invoking Java. _RUNJAVA="$JAVA_HOME"/bin/java _RUNJDB="$JAVA_HOME"/bin/jdb _RUNJAVAC="$JAVA_HOME"/bin/javac } do_stop() { echo "do_stop " if test -f $pid_file then stopPID=`cat $pid_file` echo "Tomcat stopping process id: $stopPID" fi "$_RUNJAVA" $JAVA_OPTS $CATALINA_OPTS \ -Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" -classpath "$CLASSPATH" \ -Dcatalina.base="$CATALINA_BASE" \ -Dcatalina.home="$TOMCAT_HOME" \ -Djava.io.tmpdir="$CATALINA_TMPDIR" \ org.apache.catalina.startup.Bootstrap "$@" stop # tom needs some time to stop ... sleep 6 if test -f $pid_file then /bin/rm $pid_file fi } do_start() { echo "do_start " SECURITY="" ##? add arg "-config mypath/server.xml" if [ "$1" = "-secure" ] ; then shift echo "Using Security Manager" SECURITY="-Djava.security.manager -Djava.security.policy=$CATALINA_BASE/conf/catalina.policy " fi touch "$CATALINA_BASE/logs/$CATALINA_LOG" "$_RUNJAVA" $JAVA_OPTS $CATALINA_OPTS \ -Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" -classpath "$CLASSPATH" \ $SECURITY \ -Dcatalina.base="$CATALINA_BASE" \ -Dcatalina.home="$TOMCAT_HOME" \ -Djava.io.tmpdir="$CATALINA_TMPDIR" \ org.apache.catalina.startup.Bootstrap "$@" start \ >> "$CATALINA_BASE/logs/$CATALINA_LOG" 2>&1 & #? check error $? ## make pid_file PID=$! echo $PID > $pid_file echo "Tomcat started with process id: $PID" } #------------------------------------ # main script # resolve links - $0 may be a softlink PRG="$0" while [ -h "$PRG" ]; do ls=`ls -ld "$PRG"` link=`expr "$ls" : '.*-> \(.*\)$'` if expr "$link" : '.*/.*' > /dev/null; then PRG="$link" else PRG=`dirname "$PRG"`/"$link" fi done PRGDIR=`dirname "$PRG"` # HERE=`cd "$PRGDIR/.." ; pwd` ## override (possibly) above settings if [ -r "$PRGDIR"/$runconf ]; then . "$PRGDIR"/$runconf fi if [ -r "$PRGDIR"/${runconf}.local ]; then . "$PRGDIR"/${runconf}.local fi if [ -r "$PRGDIR"/tomcatenv.sh ]; then . "$PRGDIR"/tomcatenv.sh fi # if [ -z "$TOMCAT_HOME" ] ; then # # Get standard environment variables # ## not now... # ## TOMCAT_HOME=`cd "$PRGDIR/.." ; pwd` # fi # if [ -r "$TOMCAT_HOME"/bin/setenv.sh ]; then # . "$TOMCAT_HOME"/bin/setenv.sh # fi # Get standard Java environment variables set_classpath CLASSPATH="$CLASSPATH":"$TOMCAT_HOME"/bin/bootstrap.jar if [ -z "$CATALINA_BASE" ] ; then CATALINA_BASE="$TOMCAT_HOME" fi if [ -z "$CATALINA_TMPDIR" ] ; then # Define the java.io.tmpdir to use for Catalina CATALINA_TMPDIR="$CATALINA_BASE"/temp fi if [ -z "$CATALINA_LOG" ] ; then CATALINA_LOG="catalina.out" fi #dgg pid_file="$CATALINA_BASE/logs/$CATALINA_LOG.pid" # echo "Using JAVA_HOME: $JAVA_HOME" echo "Using TOMCAT_HOME: $TOMCAT_HOME" echo "Using CATALINA_BASE: $CATALINA_BASE" echo "Logging to: $CATALINA_BASE/logs/$CATALINA_LOG" # ----- Execute The Requested Command ----------------------------------------- if [ "$1" = "graceful" ] ; then ## dgg here - check for tomcat.pid in process table shift if test -f $pid_file then PID=`cat $pid_file` if /bin/ps -p $PID | grep java > /dev/null then echo "A tomcat process is running: pid $PID" /bin/ps -fp $PID exit 0 fi fi do_start $@ elif [ "$1" = "restart" ] ; then ## dgg here - check for tomcat.pid in process table shift if test -f $pid_file then PID=`cat $pid_file` do_stop ## kill fails; use stop anyway if /bin/kill -9 $PID > /dev/null 2> /dev/null then if /bin/ps -p $PID | grep java > /dev/null then echo "A tomcat process cannnot be killed: pid $PID" /bin/ps -fp $PID exit 1 fi fi fi do_start $@ elif [ "$1" = "start" ] ; then shift do_start $@ elif [ "$1" = "stop" ] ; then shift do_stop $@ else echo "Usage: $0 [ command ... ]" echo "commands:" echo " start Start Tomcat server" echo " stop Stop Tomcat" echo " restart Re-Start Tomcat server" echo " graceful check for Tomcat process and start if not running " echo " start,.. -secure Start with security manager" exit 1 fi