#!/bin/sh # run-tomcat [start|stop|restart|graceful] # d.gilbert, simplified tomcat/bin/catalina.sh to run on flybase servers # feb03; jan04 update # # ----------------------------------------------------------------------------- # 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: # use $PACKAGES from install.conf(.local) to run tomcat for each service/conf/tomcat-server.xml # TOMCAT_HOME - fixed at common/servers/tomcat -- includes some conf/, shared parts # CATALINA_BASE - service/ directory, w/ webapps/, conf/??? temp/ logs/?? work/?? # .. but need packages.conf:localpath: values .. # # $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"; # # ----------------------------------------------------------------------------- ## added profile for why so much mem use by cv/go servlet... ## PROBLEMS WITH CATALINA_BASE files as part of service/ folder ## -- need base/shared symlink to common/servers/tomcat/shared ## -- need temp? or tmp; need work/ for Standalone stuff ## -- need conf/web.xml ## TOMCAT servers reconfig for Argos -- Jan04 # -- start/restart servers # install/run-tomcat2 # see logs/tc_eugenes, tc_centaurbase .. # # -- eugenes tomcat manager page # http://eugenes.org:7074/manager/html/ # # -- lucegene test # http://eugenes.org:7074/lucegene/search.jsp # uses eugenes/webapps/lucegene/ # old indices in eugenes/indices/lucegene/ # # -- ditto for centarbase, ports are defined # in eugenes/conf/tomcat-server.xml # centaurbase/conf/tomcat-server.xml # install.conf, etc should replace this fixed path ARGOS_ROOT=/bio/argos runconf="install.conf" dosecure=0 dosleep=0 # test flag use_tomcat5=0 STATUS_URI="/manager/list" # ^ change to test of bio webapps with no password; server-specific if [ -z "$DUMP_URL" ] ; then DUMP_URL="lynx -dump" # need 'lynx -auth="user:passwd"' for tomcat manager access # or curl -u "manager:passwd" fi # ----------------------------------------------------------------------------- # find_homedir - resolving softlink in $0 # assume real $0 is MY_HOME/bin/script_name # where MY_HOME/conf and other goodies are located - scarfed from ant/bin/ant find_MY_HOME() { 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 MY_HOME=`dirname "$PRG"`/.. # make it fully qualified MY_HOME=`cd "$MY_HOME" && pwd` PRG=`basename $0` # can we also find ARGOS_ROOT = MY_HOME/.. ? } # dgg, copied from setclasspath.sh set_classpath() { # echo "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" ERROR=6 ; exit $ERROR 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 " ERROR=6 ; exit $ERROR fi # if [ ! -z "$ROOT" ] ; then ARGOS_ROOT=$ROOT ; fi if [ -z "$TOMCAT_HOME" ] ; then TOMCAT_HOME="$ARGOS_ROOT/common/servers/tomcat"; 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 " ERROR=6 ; exit $ERROR 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 CLASSPATH="$CLASSPATH":"$TOMCAT_HOME"/bin/bootstrap.jar # Set standard commands for invoking Java. _RUNJAVA="$JAVA_HOME"/bin/java _RUNJDB="$JAVA_HOME"/bin/jdb # _RUNJAVAC="$JAVA_HOME"/bin/javac } set_tompaths() { # echo "set_tompaths" if [ -z "$CATALINA_BASE" ] ; then CATALINA_BASE="$TOMCAT_HOME" fi if [ -z "$CATALINA_CONF" ] ; then # need tomcat4, tomcat5 variants while testing both if [ $use_tomcat5 -eq 1 ] && [ -f "${CATALINA_BASE}/conf/tomcat5-server.xml" ] ; then CATALINA_CONF="${CATALINA_BASE}/conf/tomcat5-server.xml" elif [ -f "${CATALINA_BASE}/conf/tomcat-server.xml" ] ; then CATALINA_CONF="${CATALINA_BASE}/conf/tomcat-server.xml" else CATALINA_CONF="" fi fi if [ -z "$CATALINA_LOG" ] ; then CATALINA_LOG="tomcat.out" fi if [ -z "$CATALINA_TMPDIR" ] ; then if [ -d "$CATALINA_BASE/temp" ] ; then CATALINA_TMPDIR="$CATALINA_BASE/temp" elif [ -d "$CATALINA_BASE/tmp" ] ; then CATALINA_TMPDIR="$CATALINA_BASE/tmp" else CATALINA_TMPDIR="$TOMCAT_HOME/temp" fi fi if [ -z "$CATALINA_POLICY" ] ; then if [ -f "$CATALINA_BASE/conf/tomcat.policy" ] ; then CATALINA_POLICY="${CATALINA_BASE}/conf/tomcat.policy" else CATALINA_POLICY="${TOMCAT_HOME}/conf/catalina.policy" fi fi # TOMCAT_FLYBASE_SO=7884 - tomcat standalone # .. too many ports listed in tomcat-server.xml to parse easily :( # rely in install.conf to have it listed? need also editing here? to update ports if [ -z "$TOMCAT_PORT" ] ; then apid="" #problematic?# apid=`sed -ne 's/^ *manager_port=//p' $CATALINA_CONF` # CATALINA_CONF may not be set if [ "x$apid" != "x" ] ; then TOMCAT_PORT=$apid else TOMCAT_PORT=8080 fi fi apath="" if [ -z "$ARGOS_PATH" ]; then if [ ! -z "$ARGOS_ROOT" ]; then apath="$ARGOS_ROOT/common/system-local/bin:$ARGOS_ROOT/common/bin"; fi else apath=$ARGOS_PATH fi if [ ! -z "$apath" ]; then PATH="${apath}:${PATH}" ; export PATH; fi STATUSURL="http://localhost:$TOMCAT_PORT$STATUS_URI" log_file="$TOMCAT_HOME/logs/$CATALINA_LOG" CATALINA_PID="${log_file}.pid" cat </dev/null ; then STATUS="tomcat (pid $PID) running" RUNNING=1 else STATUS="tomcat (pid $PID?) not running" RUNNING=0 fi else STATUS="tomcat (no pid file) not running" RUNNING=0 PID=0 fi } get_catargs() { # echo "get_catargs" catargs="" if [ ! -z "$CATALINA_CONF" ] ; then catargs="$catargs -config $CATALINA_CONF"; fi; if [ ! -z "$debug" ] ; then catargs="$catargs -debug"; fi; #-nonaming } do_stop() { echo "do_stop $@" if [ $RUNNING -eq 0 ] ; then echo "$0 : $STATUS" return fi ## this does call to shutdown portnum in tomcat-server.xml, independent of PID "$_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 ## URK! Tomcat5 Bootstrap stop ignores args -config file path; ## fails to find default server.xml and dies ## can we use new 'stopd' command instead? -- no help, try instead startup.Catalina stop ## org.apache.catalina.startup.Bootstrap "$@" stopd ## org.apache.catalina.startup.Catalina "$@" stop ## ## ^^ no good; classes not loaded as Bootstrap does ERROR=$? ## catalina reads SHUTDOWN command from conf.xml; does System.exit(1) on start/stop exception ## always force kill? sleep 1 if kill -0 $PID 2>/dev/null ; then do_kill elif [ $ERROR -eq 0 ] ; then echo "$0 : tomcat stopped (pid $PID)" if test -f $CATALINA_PID ; then /bin/rm $CATALINA_PID fi RUNNING=0 # tom sometimes needs time to stop ... how long? dosleep=5 else echo "$0 : tomcat could not be stopped (pid $PID)" ERROR=4 fi } do_kill() { echo "do_kill $@" if [ $RUNNING -eq 0 ] ; then echo "$0 : $STATUS" return fi if kill -KILL $PID ; then echo "$0 : tomcat killed (pid $PID)" if test -f $CATALINA_PID ; then /bin/rm $CATALINA_PID fi RUNNING=0 else echo "$0 : tomcat could not be killed (pid $PID)" ERROR=4 fi } do_start() { echo "do_start $@" if [ $RUNNING -eq 1 ] ; then echo "$0 : tomcat (pid $PID) already running" return fi ##? add arg "-config mypath/server.xml" SECURITY="" if [ $dosecure -eq 1 ] ; then echo "Using Security Manager" SECURITY="-Djava.security.manager -Djava.security.policy=$CATALINA_POLICY " ## why does catalina.sh use '-Djava.security.policy==$CATALINA_POLICY' fi # startup.Catalina args: -config {pathname} [ -debug ] [ -nonaming ] { start | stop }" # startup.Bootstrap args: -debug touch "$log_file" "$_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 \ >> "$log_file" 2>&1 & PID=$! ERROR=$? #? check error $? if [ $ERROR -eq 0 ] ; then echo "$0 : tomcat started (pid $PID)" echo $PID > $CATALINA_PID else echo "$0 : tomcat could not be started (pid $PID?)" ERROR=3 fi } # Hprof usage: -Xrunhprof[:help]|[