You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by jean-frederic clere <jf...@fujitsu-siemens.com> on 2005/04/21 11:39:27 UTC

bugs 34140 and 34199

Hi,

Those 2 are reported against Daemon, but the user is looking for a "safe" way to 
know that Tomcat is completly up (AJP connector ready) or completly down. In 
jsvc the completly down case is easy: the JVM has exited.

Any hints for the completly up case?

Cheers

Jean-frederic

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


Re: bugs 34140 and 34199

Posted by jean-frederic clere <jf...@fujitsu-siemens.com>.
Thanks ;-)

I will do the following:
1 - Add a switch to jsvc to stop the service (doing in C what Henri is doing in 
his shell script).

2 - Add a switch to jsvc to wait until the controller process reaches its loop 
by doing the following:
create_tmp_file();
while (!stopping) sleep(60); /* pause() not threadsafe */
remove_tmp_file();

Any comments?

Cheers

Jean-Frederic

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


Re: bugs 34140 and 34199

Posted by Henri Gomez <he...@gmail.com>.
2005/4/22, Ian F. Darwin <ia...@darwinsys.com>:
> Henri Gomez wrote:
> 
> >I know that but if your starter wrapper check if the process whom pid
> >is stored on the file is still alive it could determine if the process
> >has been aborted via kill -9.
> >
> >I'm using this kind of hack in Linux init.d rc for at least 2 years,
> >whitout problems
> >
> >
> >
> Right, if you read the PID and send it a signal to ensure it's still
> alive at the OS level, you get quite a bit of reliability.

Here's part of my init.d script :

....

TOMCAT_CFG="/etc/tomcat55/conf/tomcat55.conf"
[ -r "$TOMCAT_CFG" ] && . "${TOMCAT_CFG}"

if [ -x /etc/rc.d/init.d/functions ]; then
. /etc/rc.d/init.d/functions
else
# Check if $pid (could be plural) are running
checkpid() {
        local i

        for i in $* ; do
                [ -d "/proc/$i" ] && return 0
        done
        return 1
}
fi

....

start() {
    echo -n "Starting $TOMCAT_PROG: "

    if [ -f /var/lock/subsys/tomcat55 ] ; then
        read kpid < /var/run/tomcat55.pid
        if checkpid $kpid 2>&1; then
            echo "process allready running"
            return -1
        else
            echo "lock file found but no process running for pid
$kpid, continuing"
        fi
    fi
   if [ -x /etc/rc.d/init.d/functions ]; then
        daemon --user $TOMCAT_USER $TOMCAT_SCRIPT start
    else
        su - $TOMCAT_USER -c "$TOMCAT_SCRIPT start"
    fi
    RETVAL=$?
    echo
    [ $RETVAL = 0 ] && touch /var/lock/subsys/tomcat55
    return $RETVAL
}


stop() {
    echo -n "Stopping $TOMCAT_PROG: "

    if [ -f /var/lock/subsys/tomcat55 ] ; then
        if [ -x /etc/rc.d/init.d/functions ]; then
            daemon --user $TOMCAT_USER $TOMCAT_SCRIPT stop
        else
            su - $TOMCAT_USER -c "$TOMCAT_SCRIPT stop"
        fi
        RETVAL=$?
        echo

        RETVAL=$?
        echo

        if [ $RETVAL = 0 ]; then
            let count=0;

            if [ -f /var/run/tomcat55.pid ] && [ ! -z
/var/run/tomcat55.pid ]; then

                read kpid < /var/run/tomcat55.pid
                let kwait=$SHUTDOWN_WAIT

                until [ `ps --pid $kpid | grep -c $kpid` = '0' ] || [
$count -gt $kwait ]
                do
                    echo "waiting for processes to finish";
                    sleep 1
                    let count=$count+1;
                done

                if [ $count -gt $kwait ]; then
                    echo "killing processes which didn't stop after
$SHUTDOWN_WAIT seconds"
                    /bin/kill -9 $kpid
                fi
            fi

            rm -f /var/lock/subsys/tomcat55 /var/run/tomcat55.pid
        fi
    fi
}


part of my TOMCAT_SCRIPT :

TOMCAT_CFG="/etc/tomcat55/conf/tomcat55.conf"
[ -r "$TOMCAT_CFG" ] && . "${TOMCAT_CFG}"

java ${JAVA_OPTS} ${HEADLESS}
-Djava.endorsed.dirs=/var/tomcat55/common/endorsed
-Dcatalina.base=/var/tomcat55 -Dcatalina.home=/var/tomcat55
-Djava.io.tmpdir=/var/tomcat55/temp -classpath ${CLASSPATH}
org.apache.catalina.startup.Bootstrap $@ >>
/var/log/tomcat55/tomcat55.log 2>&1 &

if [ ! -z "$TOMCAT_PID" ] && [ "$1" != "stop" ] ; then
    echo $! > $TOMCAT_PID
fi

As you could see the TOMCAT_SCRIPT grab the tomcat main process id via $!

Bash power :-)

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


Re: bugs 34140 and 34199

Posted by "Ian F. Darwin" <ia...@darwinsys.com>.
Henri Gomez wrote:

>I know that but if your starter wrapper check if the process whom pid
>is stored on the file is still alive it could determine if the process
>has been aborted via kill -9.
>
>I'm using this kind of hack in Linux init.d rc for at least 2 years,
>whitout problems
>
>  
>
Right, if you read the PID and send it a signal to ensure it's still 
alive at the OS level, you get quite a bit of reliability.

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


Re: bugs 34140 and 34199

Posted by Henri Gomez <he...@gmail.com>.
I know that but if your starter wrapper check if the process whom pid
is stored on the file is still alive it could determine if the process
has been aborted via kill -9.

I'm using this kind of hack in Linux init.d rc for at least 2 years,
whitout problems

2005/4/21, Ian F. Darwin <ia...@darwinsys.com>:
> Henri Gomez wrote:
> 
> >Many way :
> >
> >- check the AJP port is listening on the right port.
> >
> >- Add a 'status' file in AJP support created after AJP is completly up
> >and destroyed when AJP is closing.
> >
> >BTW, it will be better to have such file created when Tomcat is fully
> >started (independant from AJP which could be disactivated by conf) and
> >destroyed just before Tomcat stop. And if you could get the initial
> >process/job id and pass it to tomcat, it could fill this fill with
> >such jobid.
> >
> >
> Anything depending on files will give "false positives" when Tomcat is
> hit by kill -9 (on unix, or equiv on others), dies to to a JVM crash, or
> hangs after an "out of memory" error. You'd need to update the file
> periodically in the server and have a client API for checking the timestamp.
> 
> So I think the AJP port maybe more reliable, but it, too, will give
> false + if the server gets hung.
> 
> Maybe there should be a simple optional new "IsActiveConnector", if you
> enable it in config, then connect to it and send a message, it responds
> if it things the server is running correctly.  Oh, well, then why not
> just send a simple HTTP request? The IsActiveConnector is fairly simple
> to implement, but is it a good idea?
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org
> 
>

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


Re: bugs 34140 and 34199

Posted by "Ian F. Darwin" <ia...@darwinsys.com>.
Henri Gomez wrote:

>Many way :
>
>- check the AJP port is listening on the right port.
>
>- Add a 'status' file in AJP support created after AJP is completly up
>and destroyed when AJP is closing.
>
>BTW, it will be better to have such file created when Tomcat is fully
>started (independant from AJP which could be disactivated by conf) and
>destroyed just before Tomcat stop. And if you could get the initial
>process/job id and pass it to tomcat, it could fill this fill with
>such jobid.
>  
>
Anything depending on files will give "false positives" when Tomcat is 
hit by kill -9 (on unix, or equiv on others), dies to to a JVM crash, or 
hangs after an "out of memory" error. You'd need to update the file 
periodically in the server and have a client API for checking the timestamp.

So I think the AJP port maybe more reliable, but it, too, will give 
false + if the server gets hung.

Maybe there should be a simple optional new "IsActiveConnector", if you 
enable it in config, then connect to it and send a message, it responds 
if it things the server is running correctly.  Oh, well, then why not 
just send a simple HTTP request? The IsActiveConnector is fairly simple 
to implement, but is it a good idea?

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


Re: bugs 34140 and 34199

Posted by Henri Gomez <he...@gmail.com>.
Many way :

- check the AJP port is listening on the right port.

- Add a 'status' file in AJP support created after AJP is completly up
and destroyed when AJP is closing.

BTW, it will be better to have such file created when Tomcat is fully
started (independant from AJP which could be disactivated by conf) and
destroyed just before Tomcat stop. And if you could get the initial
process/job id and pass it to tomcat, it could fill this fill with
such jobid.

2005/4/21, jean-frederic clere <jf...@fujitsu-siemens.com>:
> Hi,
> 
> Those 2 are reported against Daemon, but the user is looking for a "safe" way to
> know that Tomcat is completly up (AJP connector ready) or completly down. In
> jsvc the completly down case is easy: the JVM has exited.
> 
> Any hints for the completly up case?
> 
> Cheers
> 
> Jean-frederic
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org
> 
>

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