tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r832632 - in /tomcat/tc6.0.x/trunk: STATUS.txt bin/catalina.sh webapps/docs/changelog.xml
Date Wed, 04 Nov 2009 00:24:43 GMT
Author: markt
Date: Wed Nov  4 00:24:43 2009
New Revision: 832632

URL: http://svn.apache.org/viewvc?rev=832632&view=rev
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=47699
Better handling of PID files

Modified:
    tomcat/tc6.0.x/trunk/STATUS.txt
    tomcat/tc6.0.x/trunk/bin/catalina.sh
    tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml

Modified: tomcat/tc6.0.x/trunk/STATUS.txt
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/STATUS.txt?rev=832632&r1=832631&r2=832632&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/STATUS.txt (original)
+++ tomcat/tc6.0.x/trunk/STATUS.txt Wed Nov  4 00:24:43 2009
@@ -142,15 +142,6 @@
   +1: markt
   -1: 
 
-* Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=47699
-  Better handling of PID files
-  https://issues.apache.org/bugzilla/attachment.cgi?id=24202
-  +1: markt, funkman
-  +1: fhanik (although, on .sh, I think we could get rid of 'Bootstrap stop' by now, shutdown
hooks have been available for quite some time)
-  -1: 
-   
-  
-
 * Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=44041
   Threading issue in classloading. Adds a sync so please check performance
   http://svn.apache.org/viewvc?rev=805182&view=rev 

Modified: tomcat/tc6.0.x/trunk/bin/catalina.sh
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/bin/catalina.sh?rev=832632&r1=832631&r2=832632&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/bin/catalina.sh (original)
+++ tomcat/tc6.0.x/trunk/bin/catalina.sh Wed Nov  4 00:24:43 2009
@@ -291,6 +291,13 @@
 
 elif [ "$1" = "start" ] ; then
 
+  if [ ! -z "$CATALINA_PID" ]; then
+    if [ -f "$CATALINA_PID" ]; then
+      echo "PID file ($CATALINA_PID) found. Is Tomcat still running? Start aborted."
+      exit 1
+    fi
+  fi
+
   shift
   touch "$CATALINA_BASE"/logs/catalina.out
   if [ "$1" = "-security" ] ; then
@@ -308,9 +315,6 @@
       org.apache.catalina.startup.Bootstrap "$@" start \
       >> "$CATALINA_BASE"/logs/catalina.out 2>&1 &
 
-      if [ ! -z "$CATALINA_PID" ]; then
-        echo $! > $CATALINA_PID
-      fi
   else
     "$_RUNJAVA" "$LOGGING_CONFIG" $JAVA_OPTS $CATALINA_OPTS \
       -Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" -classpath "$CLASSPATH" \
@@ -320,20 +324,44 @@
       org.apache.catalina.startup.Bootstrap "$@" start \
       >> "$CATALINA_BASE"/logs/catalina.out 2>&1 &
 
-      if [ ! -z "$CATALINA_PID" ]; then
-        echo $! > $CATALINA_PID
-      fi
+  fi
+
+  if [ ! -z "$CATALINA_PID" ]; then
+    echo $! > $CATALINA_PID
   fi
 
 elif [ "$1" = "stop" ] ; then
 
   shift
+
+  SLEEP=5
+  if [ ! -z "$1" ]; then
+    echo $1 | grep "[^0-9]" > /dev/null 2>&1
+    if [ $? -eq 1 ]; then
+      SLEEP=$1
+      shift
+    fi
+  fi
+
   FORCE=0
   if [ "$1" = "-force" ]; then
     shift
     FORCE=1
   fi
 
+  if [ ! -z "$CATALINA_PID" ]; then
+    if [ -f "$CATALINA_PID" ]; then
+      kill -0 `cat $CATALINA_PID` >/dev/null 2>&1
+      if [ $? -eq 1 ]; then
+        echo "PID file ($CATALINA_PID) found but no matching process was found. Stop aborted."
+        exit 1
+      fi
+    else
+      echo "\$CATALINA_PID was set ($CATALINA_PID) but the specified file does not exist.
Is Tomcat running? Stop aborted."
+      exit 1
+    fi
+  fi
+  
   "$_RUNJAVA" $JAVA_OPTS \
     -Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" -classpath "$CLASSPATH" \
     -Dcatalina.base="$CATALINA_BASE" \
@@ -341,12 +369,36 @@
     -Djava.io.tmpdir="$CATALINA_TMPDIR" \
     org.apache.catalina.startup.Bootstrap "$@" stop
 
+  if [ ! -z "$CATALINA_PID" ]; then
+    if [ -f "$CATALINA_PID" ]; then
+      while [ $SLEEP -ge 0 ]; do 
+        kill -0 `cat $CATALINA_PID` >/dev/null 2>&1
+        if [ $? -eq 1 ]; then
+          rm $CATALINA_PID
+          break
+        fi
+        if [ $SLEEP -gt 0 ]; then
+          sleep 1
+        fi
+        if [ $SLEEP -eq 0 ]; then
+          if [ $FORCE -eq 0 ]; then
+            echo "Tomcat did not stop in time. PID file was not removed."
+          fi
+        fi
+        SLEEP=`expr $SLEEP - 1 `
+      done
+    fi
+  fi
+
   if [ $FORCE -eq 1 ]; then
-    if [ ! -z "$CATALINA_PID" ]; then
-       echo "Killing: `cat $CATALINA_PID`"
-       kill -9 `cat $CATALINA_PID`
+    if [ -z "$CATALINA_PID" ]; then
+      echo "Kill failed: \$CATALINA_PID not set"
     else
-       echo "Kill failed: \$CATALINA_PID not set"
+      if [ -f "$CATALINA_PID" ]; then
+        echo "Killing: `cat $CATALINA_PID`"
+        kill -9 `cat $CATALINA_PID`
+        rm $CATALINA_PID
+      fi
     fi
   fi
 
@@ -372,9 +424,12 @@
   echo "  run -security     Start in the current window with security manager"
   echo "  start             Start Catalina in a separate window"
   echo "  start -security   Start in a separate window with security manager"
-  echo "  stop              Stop Catalina"
-  echo "  stop -force       Stop Catalina (followed by kill -KILL)"
+  echo "  stop              Stop Catalina, waiting up to 5 seconds for the process to end"
+  echo "  stop n            Stop Catalina, waiting up to n seconds for the process to end"
+  echo "  stop -force       Stop Catalina, wait up to 5 seconds and then use kill -KILL if
still running"
+  echo "  stop n -force     Stop Catalina, wait up to n seconds and then use kill -KILL if
still running"
   echo "  version           What version of tomcat are you running?"
+  echo "Note: Waiting for the process to end and use of the -force option require that \$CATALINA_PID
is defined"
   exit 1
 
 fi

Modified: tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml?rev=832632&r1=832631&r2=832632&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml Wed Nov  4 00:24:43 2009
@@ -489,6 +489,9 @@
         per JAR as required. (markt)
       </add>
       <fix>
+        <bug>47699</bug>: Provide better handling of PID files. (markt)
+      </fix>
+      <fix>
         <bug>47824</bug>: Make Servlet API an optional dependency for JULI when
         using Maven. (markt)
       </fix>



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message