You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2009/08/17 15:01:32 UTC

svn commit: r804963 - /tomcat/trunk/bin/catalina.sh

Author: markt
Date: Mon Aug 17 13:01:31 2009
New Revision: 804963

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

Modified:
    tomcat/trunk/bin/catalina.sh

Modified: tomcat/trunk/bin/catalina.sh
URL: http://svn.apache.org/viewvc/tomcat/trunk/bin/catalina.sh?rev=804963&r1=804962&r2=804963&view=diff
==============================================================================
--- tomcat/trunk/bin/catalina.sh (original)
+++ tomcat/trunk/bin/catalina.sh Mon Aug 17 13:01:31 2009
@@ -287,6 +287,11 @@
 
 elif [ "$1" = "start" ] ; then
 
+  if [ ! -z "$CATALINA_PID" -a -e "$CATALINA_PID" ]; then
+    echo "PID file found. Is Tomcat still running? This start aborted"
+    exit 1
+  fi
+
   shift
   touch "$CATALINA_BASE"/logs/catalina.out
   if [ "$1" = "-security" ] ; then
@@ -302,9 +307,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" \
@@ -314,14 +316,22 @@
       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" -a $1 -eq $1 &>/dev/null ]; then
+    SLEEP=$1
+    shift
+  fi
+
   FORCE=0
   if [ "$1" = "-force" ]; then
     shift
@@ -335,12 +345,33 @@
     -Djava.io.tmpdir="$CATALINA_TMPDIR" \
     org.apache.catalina.startup.Bootstrap "$@" stop
 
+  if [ ! -z "$CATALINA_PID" -a -e "$CATALINA_PID" ]; then
+    while [ $SLEEP -ge 0 ] 
+    do
+      if ! kill -0 `cat $CATALINA_PID` &>/dev/null; then
+        rm $CATALINA_PID
+        break
+      fi
+      if [ $SLEEP -gt 0 ]; then
+        sleep 1
+      fi
+      let SLEEP=SLEEP-1 
+    done
+  else
+    if [ $? -eq 0 ]; then
+      sleep $SLEEP
+    fi  
+  fi
+
   if [ $FORCE -eq 1 ]; then
-    if [ ! -z "$CATALINA_PID" ]; then
+    if [ ! -z "$CATALINA_PID" -a -e "$CATALINA_PID" ]; then
        echo "Killing: `cat $CATALINA_PID`"
        kill -9 `cat $CATALINA_PID`
+       rm $CATALINA_PID
     else
-       echo "Kill failed: \$CATALINA_PID not set"
+       if [ -z "$CATALINA_PID" ]; then
+         echo "Kill failed: \$CATALINA_PID not set"
+       fi
     fi
   fi
 
@@ -367,7 +398,9 @@
   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 n            Stop Catalina, waiting n seconds for the process to end"
   echo "  stop -force       Stop Catalina (followed by kill -KILL)"
+  echo "  stop n -force     Stop Catalina, wait n seconds and then use kill -KILL if still running"
   echo "  version           What version of tomcat are you running?"
   exit 1
 



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


Re: svn commit: r804963 - /tomcat/trunk/bin/catalina.sh

Posted by sebb <se...@gmail.com>.
On 17/08/2009, Mark Thomas <ma...@apache.org> wrote:
> sebb wrote:
>  > On 17/08/2009, markt@apache.org <ma...@apache.org> wrote:
>
> >>  +  else
>  >>  +    if [ $? -eq 0 ]; then
>  >
>  > Might be better to check $FORCE before sleeping?
>
>
> On reflection, I don't think there is any need for a sleep here at all.
>  There is no PID so force won't be able to do anything anyway.
>
>
>  > Surely that should be:
>  >
>  > echo "  stop              Stop Catalina, waiting up to 5 seconds for
>  > the process to end"
>
>
> With the above change, waiting and force require the use of a PID file.
>  I'll add that to the end of the usage.

OK, sounds good.

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

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


Re: svn commit: r804963 - /tomcat/trunk/bin/catalina.sh

Posted by Mark Thomas <ma...@apache.org>.
sebb wrote:
> On 17/08/2009, markt@apache.org <ma...@apache.org> wrote:
>>  +  else
>>  +    if [ $? -eq 0 ]; then
> 
> Might be better to check $FORCE before sleeping?

On reflection, I don't think there is any need for a sleep here at all.
There is no PID so force won't be able to do anything anyway.

> Surely that should be:
> 
> echo "  stop              Stop Catalina, waiting up to 5 seconds for
> the process to end"

With the above change, waiting and force require the use of a PID file.
I'll add that to the end of the usage.

Mark



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


Re: svn commit: r804963 - /tomcat/trunk/bin/catalina.sh

Posted by sebb <se...@gmail.com>.
On 17/08/2009, markt@apache.org <ma...@apache.org> wrote:
> Author: markt
>  Date: Mon Aug 17 13:01:31 2009
>  New Revision: 804963
>
>  URL: http://svn.apache.org/viewvc?rev=804963&view=rev
>  Log:
>  Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=47699\nBetter handling of PID files
>
>  Modified:
>     tomcat/trunk/bin/catalina.sh
>
>  Modified: tomcat/trunk/bin/catalina.sh
>  URL: http://svn.apache.org/viewvc/tomcat/trunk/bin/catalina.sh?rev=804963&r1=804962&r2=804963&view=diff
>  ==============================================================================
>  --- tomcat/trunk/bin/catalina.sh (original)
>  +++ tomcat/trunk/bin/catalina.sh Mon Aug 17 13:01:31 2009
>  @@ -287,6 +287,11 @@
>
>   elif [ "$1" = "start" ] ; then
>
>  +  if [ ! -z "$CATALINA_PID" -a -e "$CATALINA_PID" ]; then
>  +    echo "PID file found. Is Tomcat still running? This start aborted"
>  +    exit 1
>  +  fi
>  +
>    shift
>    touch "$CATALINA_BASE"/logs/catalina.out
>    if [ "$1" = "-security" ] ; then
>  @@ -302,9 +307,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" \
>  @@ -314,14 +316,22 @@
>        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" -a $1 -eq $1 &>/dev/null ]; then
>  +    SLEEP=$1
>  +    shift
>  +  fi
>  +
>    FORCE=0
>    if [ "$1" = "-force" ]; then
>      shift
>  @@ -335,12 +345,33 @@
>      -Djava.io.tmpdir="$CATALINA_TMPDIR" \
>      org.apache.catalina.startup.Bootstrap "$@" stop
>
>  +  if [ ! -z "$CATALINA_PID" -a -e "$CATALINA_PID" ]; then
>  +    while [ $SLEEP -ge 0 ]
>  +    do
>  +      if ! kill -0 `cat $CATALINA_PID` &>/dev/null; then
>  +        rm $CATALINA_PID
>  +        break
>  +      fi
>  +      if [ $SLEEP -gt 0 ]; then
>  +        sleep 1
>  +      fi
>  +      let SLEEP=SLEEP-1
>  +    done
>  +  else
>  +    if [ $? -eq 0 ]; then

Might be better to check $FORCE before sleeping?

>  +      sleep $SLEEP
>  +    fi
>  +  fi
>  +
>    if [ $FORCE -eq 1 ]; then
>  -    if [ ! -z "$CATALINA_PID" ]; then
>  +    if [ ! -z "$CATALINA_PID" -a -e "$CATALINA_PID" ]; then
>         echo "Killing: `cat $CATALINA_PID`"
>         kill -9 `cat $CATALINA_PID`
>  +       rm $CATALINA_PID
>      else
>  -       echo "Kill failed: \$CATALINA_PID not set"
>  +       if [ -z "$CATALINA_PID" ]; then
>  +         echo "Kill failed: \$CATALINA_PID not set"
>  +       fi
>      fi
>    fi
>
>  @@ -367,7 +398,9 @@
>    echo "  start             Start Catalina in a separate window"
>    echo "  start -security   Start in a separate window with security manager"
>    echo "  stop              Stop Catalina"

Surely that should be:

echo "  stop              Stop Catalina, waiting up to 5 seconds for
the process to end"

>  +  echo "  stop n            Stop Catalina, waiting n seconds for the process to end"

s/n/upto n/

>    echo "  stop -force       Stop Catalina (followed by kill -KILL)"

Likewise

>  +  echo "  stop n -force     Stop Catalina, wait n seconds and then use kill -KILL if still running"

Likewise

>    echo "  version           What version of tomcat are you running?"
>    exit 1
>
>
>
>
>  ---------------------------------------------------------------------
>  To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
>  For additional commands, e-mail: dev-help@tomcat.apache.org
>
>

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