Ok, I think I've finished with the obvious fixes today:) Here it comes...
-- Nicolas Mailhot
#!/bin/sh # # $Id: tomcat.sh,v 1.32 2002/01/31 03:58:13 larryi Exp $ # Shell script to start and stop the server # There are other, simpler commands to startup the runner. The two # commented commands good replacements. The first works well with # Java Platform 1.1 based runtimes. The second works well with # Java2 Platform based runtimes. #jre -cp lib/tomcat.jar org.apache.tomcat.startup.Main $* #java -cp lib/tomcat.jar org.apache.tomcat.startup.Main $* #java -jar lib/tomcat.jar # Define and read this script configuration file TOMCAT_CFG="/etc/tomcat3/conf/tomcat3.conf" [ -r "$TOMCAT_CFG" ] && . "${TOMCAT_CFG}" [ -x /etc/rc.d/init.d/functions ] && . /etc/rc.d/init.d/functions # This function will do its best to find a JAVA_HOME # It intentionnaly have the same name as the one defined # in the JPackage project jpackage-utils rpm to enable # easy drop-in of jpackage functions later set_jvm() { # Search for java in PATH JAVA=`which java` if [ -z "$JAVA" ] ; then JAVA_BINDIR=`dirname ${JAVA}` JAVA_HOME="${JAVA_BINDIR}/.." fi # Default clean JAVA_HOME [ -z "$JAVA_HOME" -a -d "/usr/lib/java" ] && JAVA_HOME="/usr/lib/java" # Default IBMs JAVA_HOME SDK 1.3 and 1.3.1 [ -z "$JAVA_HOME" -a -d "/opt/IBMJava2-131" ] && JAVA_HOME="/opt/IBMJava2-131" [ -z "$JAVA_HOME" -a -d "/opt/IBMJava2-13" ] && JAVA_HOME="/opt/IBMJava2-13" # Another solution [ -z "$JAVA_HOME" -a -d "/usr/java/jdk" ] && JAVA_HOME="/usr/java/jdk" # madeinlinux JAVA_HOME [ -z "$JAVA_HOME" -a -d "/usr/local/jdk1.2.2" ] && JAVA_HOME="/usr/local/jdk1.2.2" # Kondara JAVA_HOME [ -z "$JAVA_HOME" -a -d "/usr/lib/java/jdk1.2.2" ] && JAVA_HOME="/usr/lib/java/jdk1.2.2" # Other commonly found JAVA_HOMEs [ -z "$JAVA_HOME" -a -d "/usr/jdk1.2" ] && JAVA_HOME="/usr/jdk1.2" # Default Caldera JAVA_HOME [ -z "$JAVA_HOME" -a -d "/opt/java-1.3" ] && JAVA_HOME="/opt/java-1.3" # Add other locations here if [ -z "$JAVA_HOME" ]; then echo "No JAVA_HOME specified in ${TOMCAT_CFG} and no java found, exiting..." exit 1 fi } # This function with fill any still undeclared variable # with default values, clear the classpath and add # tomcat policy to tomcat options fillvalues() { [ -z "$JAVA_HOME" ] && set_jvm [ -z "$JAVACMD" ] && JAVACMD="$JAVA_HOME/bin/java" [ -z "$TOMCAT_AJPID" ] && TOMCAT_AJPID=/var/spool/tomcat3/ajp.id [ -z "$TOMCAT_AJP12ID" ] && TOMCAT_AJP12ID=/var/spool/tomcat3/ajp12.id [ -z "$TOMCAT_AJP13ID" ] && TOMCAT_AJP13ID=/var/spool/tomcat3/ajp13.id [ -z "$TOMCAT_RUN" ] && TOMCAT_RUN=/var/log/tomcat3/tomcat3.pid [ -z "$TOMCAT_PID" ] && TOMCAT_PID=/var/log/tomcat3/tomcat.pid [ -z "$TOMCAT_LOG" ] && TOMCAT_LOG=/var/log/tomcat3/tomcat.log [ -z "$STDOUT_LOG" ] && STDOUT_LOG=$TOMCAT_LOG [ -z "$STDERR_LOG" ] && STDERR_LOG=$STDOUT_LOG ## Unconditional part MAIN=org.apache.tomcat.startup.Main # Ignore previous CLASSPATH ; this is consistent with "java -jar tomcat.jar " # (we really don't need to export it, it only serves to justify more logic at # the end of this script to restore the original value) oldCP=CLASSPATH CLASSPATH=${TOMCAT_INSTALL}/lib/tomcat.jar # Process options : add tomcat.policy, # even if we don't use sandbox, it doesn't hurt TOMCAT_OPTS="$TOMCAT_OPTS -Djava.security.policy==${TOMCAT_HOME}/conf/tomcat.policy " TOMCATCMD="$JAVACMD $TOMCAT_OPTS -Dtomcat.home=${TOMCAT_HOME} $MAIN" } # This function will adjust the limits under which tomcat will run using ulimit # Note that you may still have to correct /etc/security/limits.conf to allow # the tomcat user to do this # The values used are taken from $TOMCAT_CFG adjustlimits() { [ ! -z "$ULIMIT_N" ] &&\ [ $(ulimit -n) != "unlimited" -a $(ulimit -n) -lt $ULIMIT_N ] &&\ ulimit -S -n $ULIMIT_N } # This function will parse the start of the command line # to check for known switches preparse() { for param in "$@" ; do case "$param" in -n|--noout|-q|--quiet|-b|--both) LOGT=$param ;; -i|--info|-v|--verbose) VERBOSE="true" ;; -f|--force) FORCE="true" ;; -w|--wait) WAIT="true" ;; --) break ;; *) PARSED="$PARSED $param" ;; esac done } # This function will redirect outputs depending # on the options entered on the command line log() { case "$LOGT" in -n|--noout) $@ >> $STDOUT_LOG 2>> $STDERR_LOG ;; -q|--quiet) $@ > /dev/null 2>&1 ;; -b|--both) $@ | tee -a $STDOUT_LOG ;; *) $@ esac } # This function will print various informations at startup info() { cat << EOF_INFO Java information : - Java home: $JAVA_HOME - command used: $JAVACMD - classpath: $CLASSPATH - JVM information: $($JAVACMD -version 2>&1) - provided by: $(/bin/rpm -q --whatprovides "$JAVA_HOME") Tomcat user: - defined: $TOMCAT_USER - used : $(/usr/bin/whoami) Configuration file: $TOMCAT_CFG Log to file: $TOMCAT_LOG Pid file: $TOMCAT_PID Tomcat home: $TOMCAT_HOME Limits to which tomcat will be subjected: $(ulimit -a) EOF_INFO } help() { cat <<EOF_HELP Usage: $0 [--switches] command SWITCHES -n|--noout redirect outputs to $STDOUT_LOG and $STDERR_LOG -q|--quiet quiet mode, no output -b|--both copy outputs to $STDOUT_LOG -i|--info|-v|--verbose print some status information before executing command -w|--wait (only for sart) wait until tomcat is initialized before returning -f|--force (only for stop) stop using the 'kill' command if necessary COMMANDS start start tomcat in the background run start tomcat in the foreground estart start Tomcat using the/your EmbededTomcat class which uses a hardcoded set of modules stop stop tomcat restart|reload stop tomcat then start it again enableAdmin trust the admin web application, i.e. rewrites conf/apps-admin.xml with trusted="true" env set CLASSPATH and TOMCAT_HOME env. variables jspc run jsp pre compiler jspcorig run jsp pre compiler with legacy script info print some information about the parameters Tomcat will use help print this help text EOF_HELP } start() { [ "$VERBOSE" ] && log info log $TOMCATCMD start $@ & JAVA_PID=$! echo $JAVA_PID > ${TOMCAT_PID} # Wait for ajp12.id signaling end of startup if [ "$WAIT" ] ; then WAIT=360 while [ ! -f "$TOMCAT_AJP12ID" ] ; do sleep 1 WAIT=`expr $WAIT - 1` if [ "$WAIT" = "0" ] ; then echo "Tomcat was not ready after ${MAX_WAIT} seconds, giving up waiting " break; fi done fi } stop() { [ "$VERBOSE" ] && log info log $TOMCATCMD stop -ajpid ${TOMCAT_AJP12ID} -ajp12 $@ & pid=$(cat "$TOMCAT_PID") if [ "$FORCE" ] ; then echo "Killing: $pid" # Shamelessly copied from /etc/init.d/functions if checkpid $pid 2>&1; then # TERM first, then KILL if not dead kill -TERM $pid usleep 100000 if checkpid $pid && sleep 1 && checkpid $pid && sleep 3 && checkpid $pid ; then kill -KILL $pid fi fi fi usleep 100000 checkpid $pid RETVAL=$? echo } native() { # Native commands, no further shell processing [ "$VERBOSE" ] && log info log $TOMCATCMD $@ # Try to catch a meaningful exit code RETVAL=$? echo } jspcorig() { CLASSPATH=. for i in ${TOMCAT_HOME}/lib/container/* ${TOMCAT_HOME}/lib/common/* ; do CLASSPATH=${CLASSPATH}:$i done CLASSPATH=${CLASSPATH}:${JAVA_HOME}/lib/tools.jar # Backdoor classpath setting for development purposes when all classes # are compiled into a /classes dir and are not yet jarred. [ -d ${TOMCAT_HOME}/classes ] && CLASSPATH=${TOMCAT_HOME}/classes:${CLASSPATH} [ ! -z "$oldCP" ] && CLASSPATH=${CLASSPATH}:${oldCP} (cd $TOMCAT_HOME; $JAVACMD $JSPC_OPTS -Dtomcat.home=${TOMCAT_HOME} org.apache.jasper.JspC $@) } env() { ## Call it with source tomcat.sh to set the env for tomcat echo Setting classpath to: ${CLASSPATH} # -------------------- Add all classes in common, container, apps - # Used if you want to do command-line javac, etc ## Temp - old script for i in ${TOMCAT_HOME}/lib/* ${TOMCAT_HOME}/lib/common/* ${TOMCAT_HOME}/lib/container/* ${TOMCAT_HOME}/lib/apps/* ; do if [ ! -z "$CLASSPATH" ]; then CLASSPATH=${CLASSPATH}:$i else CLASSPATH=$i fi done #For JDK1.2 environment [ -f ${JAVA_HOME}/lib/tools.jar ] && CLASSPATH=${CLASSPATH}:${JAVA_HOME}/lib/tools.jar # Backdoor classpath setting for development purposes when all classes # are compiled into a /classes dir and are not yet jarred. [ -d ${TOMCAT_HOME}/classes ] && CLASSPATH=${TOMCAT_HOME}/classes:${CLASSPATH} oldCP=$CLASSPATH } corelogic() { RETVAL=0 case "$1" in start) shift start $@ ;; stop) shift stop $@ ;; restart|reload) shift stop $@ start $@ ;; run) shift native start $@ ;; estart|jspc|enableAdmin) native $@ ;; jspcorig) shift jspcorig $@ ;; env) shift env $@ ;; info) info ;; help) help ;; *) echo "Usage: $0 {start|stop|restart|run|enableAdmin|estart|env|jspc|jspcorig|info|help}" exit 1 esac return $RETVAL } # ****************************** * # Now we will use these functions # # ****************************** * fillvalues adjustlimits preparse $@ corelogic $PARSED exit $RETVAL
signature.asc
Description: PGP signature