costin 01/03/14 23:33:19
Modified: . changes3.3
src/share/org/apache/tomcat/modules/config
ProfileLoader.java
src/share/org/apache/tomcat/modules/server
Ajp12Interceptor.java
src/share/org/apache/tomcat/startup Tomcat.java
src/shell tomcat.sh
Log:
Few more usability changes ( in the main branch )
- generate the ajp12.id file when the server is moving to "READY" state,
i.e. after all initialization ( including starting the connectors )
- added -wait option to tomcat.sh, so that the script returns when the
server is ready ( it just looks for ajp12.id file )
- added -noout option to redirect the stdout/stderr to a file
- save the PID of the java process in conf/tomcat.pid ( of course, you
don't need this because tomcat never hangs, but just in case :-)
- also, the -security option is no longer processed in the shell script,
it is part of the java start code ( and all config is now in server.xml,
including the policy file - no need to edit the shell script )
The first 2 changes will make it easier to write test scripts (
tomcat.sh will return when it's ready and you can start sending request ).
None of them should affect existing use - but may simplify some tasks
Please review - I don't know if this is needed in the BAT files
( you don't have a kill command, etc )
Revision Changes Path
1.9 +19 -0 jakarta-tomcat/changes3.3
Index: changes3.3
===================================================================
RCS file: /home/cvs/jakarta-tomcat/changes3.3,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- changes3.3 2001/03/13 23:43:47 1.8
+++ changes3.3 2001/03/15 07:33:17 1.9
@@ -113,6 +113,24 @@
-------------------- BUILD/STARTUP --------------------
+- On startup, after the server is initialized, the Ajp12Interceptor will
+ generate conf/ajp12.id containing it's port and secret ( if any ), to
+allow easy stop.
+
+- the unix start scripts now take a "-wait" option ( "tomcat.sh start -wait" )
+making the script wait until the server is started. This is good for
+automated tests.
+
+- the unix scripts will generate a conf/tomcat.pid file with the pid
+of the java process that is put in background. This should be used as
+a last resort if normal shutdown fails.
+
+- the -security option is passed and processed in Java. All sandboxing
+options are specified using PolicyInterceptor ( including the
+policy file, etc ) - the command line is no longer used. This allows
+people embeding tomcat the same control and reduces the complexity of
+the shell script.
+
- org.apache.tomcat.startup.Main now builds 3 distinct class loaders: (1)
one to be used only by the servlet container. (2) one to be shared by all
web applications and (3) one that is common to both the above.
@@ -123,6 +141,7 @@
to the 'apps' and 'common' classloaders by including them in the classpath
properties "-Dorg.apache.tomcat.apps.classpath" and
"-Dorg.apache.tomcat.common.classpath", respectively.
+
- generate separate jar files for each component ( utils, core, facade,
modules ) That insures the layers are properly separated, utils can be reused.
1.4 +1 -1
jakarta-tomcat/src/share/org/apache/tomcat/modules/config/ProfileLoader.java
Index: ProfileLoader.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/modules/config/ProfileLoader.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ProfileLoader.java 2001/03/08 18:42:43 1.3
+++ ProfileLoader.java 2001/03/15 07:33:18 1.4
@@ -363,7 +363,7 @@
ClassLoader appLoader;
Vector modules=new Vector();
- public Profile() {};
+ public Profile() {}
public String getName() {
return name;
1.13 +6 -2
jakarta-tomcat/src/share/org/apache/tomcat/modules/server/Ajp12Interceptor.java
Index: Ajp12Interceptor.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/modules/server/Ajp12Interceptor.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- Ajp12Interceptor.java 2001/02/07 07:01:25 1.12
+++ Ajp12Interceptor.java 2001/03/15 07:33:18 1.13
@@ -101,10 +101,14 @@
secret=s;
}
- public void engineInit(ContextManager cm )
+ public void engineState(ContextManager cm, int state )
throws TomcatException
{
- super.engineInit(cm);
+ if( state!=ContextManager.STATE_START )
+ return;
+ // the engine is now started, create the ajp12.id
+ // file that will allow us to stop the server and
+ // know that the server is started ok.
Ajp12Interceptor tcpCon=this;
int portInt=tcpCon.getPort();
InetAddress address=tcpCon.getAddress();
1.59 +1 -1 jakarta-tomcat/src/share/org/apache/tomcat/startup/Tomcat.java
Index: Tomcat.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/startup/Tomcat.java,v
retrieving revision 1.58
retrieving revision 1.59
diff -u -r1.58 -r1.59
--- Tomcat.java 2001/03/02 04:49:34 1.58
+++ Tomcat.java 2001/03/15 07:33:19 1.59
@@ -37,7 +37,7 @@
String configFile=null;
// relative to TOMCAT_HOME
static final String DEFAULT_CONFIG="conf/server.xml";
- SimpleHashtable attributes=new SimpleHashtable();;
+ SimpleHashtable attributes=new SimpleHashtable();
static Log log=Log.getLog( "tc_log", "Tomcat" );
public Tomcat() {
1.21 +76 -50 jakarta-tomcat/src/shell/tomcat.sh
Index: tomcat.sh
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/shell/tomcat.sh,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- tomcat.sh 2001/02/06 04:44:53 1.20
+++ tomcat.sh 2001/03/15 07:33:19 1.21
@@ -1,6 +1,6 @@
#!/bin/sh
#
-# $Id: tomcat.sh,v 1.20 2001/02/06 04:44:53 costin Exp $
+# $Id: tomcat.sh,v 1.21 2001/03/15 07:33:19 costin Exp $
# Shell script to start and stop the server
@@ -9,16 +9,19 @@
# Java Platform 1.1 based runtimes. The second works well with
# Java2 Platform based runtimes.
-#jre -cp runner.jar:servlet.jar:classes org.apache.tomcat.shell.Startup $*
-#java -cp runner.jar:servlet.jar:classes org.apache.tomcat.shell.Startup $*
+#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
-NEW_LOADER=1
-export NEW_LOADER
-
+# Read local properties
if [ -f $HOME/.tomcatrc ] ; then
. $HOME/.tomcatrc
fi
+# -------------------- Guess TOMCAT_HOME --------------------
+# Follow symbolic links to the real tomcat.sh
+# Extract the base dir.
+# Look in well-known places if this fails
if [ "$TOMCAT_HOME" = "" ] ; then
## resolve links - $0 may be a link to home
PRG=$0
@@ -75,6 +78,8 @@
JSPC_OPTS=""
fi
+## -------------------- Find JAVA_HOME --------------------
+
if [ -z "$JAVA_HOME" ] ; then
JAVA=`which java`
if [ -z "$JAVA" ] ; then
@@ -90,47 +95,22 @@
JAVACMD=$JAVA_HOME/bin/java
fi
+## -------------------- Prepare CLASSPATH --------------------
+MAIN=org.apache.tomcat.startup.Main
+export MAIN
oldCP=$CLASSPATH
-
unset CLASSPATH
-
-if [ "$NEW_LOADER" = "1" ]; then
- MAIN=org.apache.tomcat.startup.Main
- export MAIN
- CLASSPATH=${TOMCAT_HOME}/lib/tomcat.jar
-else
- MAIN=org.apache.tomcat.startup.Tomcat
-
-## Temp - old script
-for i in ${TOMCAT_HOME}/lib/* ; do
- if [ "$CLASSPATH" != "" ]; then
- CLASSPATH=${CLASSPATH}:$i
- else
- CLASSPATH=$i
- fi
-done
-
-if [ -f ${JAVA_HOME}/lib/tools.jar ] ; then
- # We are probably in a JDK1.2 environment
- CLASSPATH=${CLASSPATH}:${JAVA_HOME}/lib/tools.jar
-fi
-
-# Backdoor classpath setting for development purposes when all classes
-# are compiled into a /classes dir and are not yet jarred.
-if [ -d ${TOMCAT_HOME}/classes ]; then
- CLASSPATH=${TOMCAT_HOME}/classes:${CLASSPATH}
-fi
+CLASSPATH=${TOMCAT_HOME}/lib/tomcat.jar
if [ "$oldCP" != "" ]; then
CLASSPATH=${CLASSPATH}:${oldCP}
fi
-# End - NEW_LOADER
-fi
-
export CLASSPATH
+## -------------------- Process options --------------------
+
# We start the server up in the background for a couple of reasons:
# 1) It frees up your command window
# 2) You should use `stop` option instead of ^C to bring down the server
@@ -139,14 +119,45 @@
echo Using classpath: ${CLASSPATH}
echo Using JAVA_HOME: ${JAVA_HOME}
echo Using TOMCAT_HOME: ${TOMCAT_HOME}
- if [ "$1" = "-security" ] ; then
- echo Starting with a SecurityManager
- $JAVACMD $TOMCAT_OPTS -Djava.security.manager
-Djava.security.policy==${TOMCAT_HOME}/conf/tomcat.policy -Dtomcat.home=${TOMCAT_HOME}
$MAIN "$@" &
+
+ #Old code for -security: -Djava.security.manager
-Djava.security.policy==${TOMCAT_HOME}/conf/tomcat.policy
+ # not needed, java starter will do that automatically
+
+ if [ -f ${TOMCAT_HOME}/conf/ajp12.id ] ; then
+ rm -f ${TOMCAT_HOME}/conf/ajp12.id
+ fi
+
+ WAIT=0
+ if [ "$1" = "-wait" ] ; then
+ shift
+ # wait at least 2 min
+ WAIT=120
+ fi
+
+ if [ "$1" = "-noout" ] ; then
+ shift
+ $JAVACMD $TOMCAT_OPTS -Dtomcat.home=${TOMCAT_HOME} $MAIN "$@"
>${TOMCAT_HOME}/stdout.log 2>&1 &
else
- $JAVACMD $TOMCAT_OPTS -Dtomcat.home=${TOMCAT_HOME} $MAIN "$@" &
+ $JAVACMD $TOMCAT_OPTS -Dtomcat.home=${TOMCAT_HOME} $MAIN "$@" &
fi
-# $JAVACMD org.apache.tomcat.shell.Startup "$@" &
+
+ JAVA_PID=$!
+ echo $JAVA_PID > ${TOMCAT_HOME}/conf/tomcat.pid
+
+ # Wait for ajp12.id signaling end of startup
+ if [ ! "$WAIT" = "0" ] ; then
+ while [ ! -f ${TOMCAT_HOME}/conf/ajp12.id ] ; do
+ sleep 1
+
+ WAIT=`expr $WAIT - 1`
+ if [ "$i" = "0" ] ; then
+ echo "Tomcat was no ready after 120 seconds, giving up waiting "
+ break;
+ fi
+ done
+ fi
+
elif [ "$1" = "stop" ] ; then
shift
echo Using classpath: ${CLASSPATH}
@@ -160,14 +171,7 @@
echo Using classpath: ${CLASSPATH}
echo Using JAVA_HOME: ${JAVA_HOME}
echo Using TOMCAT_HOME: ${TOMCAT_HOME}
- if [ "$1" = "-security" ] ; then
- echo Starting with a SecurityManager
- $JAVACMD $TOMCAT_OPTS -Djava.security.manager
-Djava.security.policy==${TOMCAT_HOME}/conf/tomcat.policy -Dtomcat.home=${TOMCAT_HOME}
$MAIN "$@"
- else
$JAVACMD $TOMCAT_OPTS -Dtomcat.home=${TOMCAT_HOME} $MAIN "$@"
- fi
-# $JAVACMD org.apache.tomcat.shell.Startup "$@"
- # no &
elif [ "$1" = "ant" ] ; then
shift
@@ -183,6 +187,27 @@
## Call it with source tomcat.sh to set the env for tomcat
shift
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 [ "$CLASSPATH" != "" ]; then
+ CLASSPATH=${CLASSPATH}:$i
+ else
+ CLASSPATH=$i
+ fi
+ done
+
+ if [ -f ${JAVA_HOME}/lib/tools.jar ] ; then
+ # We are probably in a JDK1.2 environment
+ CLASSPATH=${CLASSPATH}:${JAVA_HOME}/lib/tools.jar
+ fi
+
+ # Backdoor classpath setting for development purposes when all classes
+ # are compiled into a /classes dir and are not yet jarred.
+ if [ -d ${TOMCAT_HOME}/classes ]; then
+ CLASSPATH=${TOMCAT_HOME}/classes:${CLASSPATH}
+ fi
oldCP=$CLASSPATH
else
@@ -190,7 +215,8 @@
echo "tomcat (start|env|run|stop|ant)"
echo " start - start tomcat in the background"
echo " run - start tomcat in the foreground"
- echo " -security - use a SecurityManager when starting"
+ echo " run -wait - wait until tomcat is initialized before returning "
+ echo " -security - use a SecurityManager when starting"
echo " stop - stop tomcat"
echo " env - set CLASSPATH and TOMCAT_HOME env. variables"
echo " ant - run ant script in tomcat context ( classes, directories,
etc)"