tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Arieh Markel <Arieh.Mar...@Central.Sun.COM>
Subject Determining that init phase has completed (was Re: Is KSH "officially" needed?)
Date Wed, 15 Dec 1999 18:02:32 GMT

> Mailing-List: contact tomcat-dev-help@jakarta.apache.org; run by ezmlm
> X-No-Archive: yes
> list-help: <mailto:tomcat-dev-help@jakarta.apache.org>
> list-unsubscribe: <mailto:tomcat-dev-unsubscribe@jakarta.apache.org>
> list-post: <mailto:tomcat-dev@jakarta.apache.org>
> Delivered-To: mailing list tomcat-dev@jakarta.apache.org
> From: Costin.Manolache@eng.sun.com
> To: tomcat-dev@jakarta.apache.org
> Subject: Re: Is KSH "officially" needed?
> 
> Paul Philion wrote:
> 
> > Costin -
> >
> > The reason I mention it is because the "build/tomcat/test/runtest.sh"
> > winds up with ksh. This is based on
> >
> >   jakarta-tomcat/src/tests/bin/runtest.sh
> >
> > Which has your name on it. ;-)
> 
> :-)
> 
> I just cut&pasted it, and since I had ksh...
> 
> Both runtest.sh are bad, not because ksh but because of that
> sleep that can't be avoided and it's either too long or too
> short.
> The problem is in tomcat - which should notify somehow that he is done
> initializing, so next process can start doing something.

We have resolved the same problem in a Java application that we wrote with
the code excerpts that follow.

The idea was based on the creation of a 'lock file' by the initializing
script, and its removal by the Java program at the point that it can
advertise the fact that it has finished the initialization.

The script, in its part, loops/sleeps, until he realizes that the 'lock file'
no longer exists.

To prevent endless loops, the loop/sleep is constrained to a number of iterations,
and the existence of the forked process is validated (with a kill -0 $!).

Here is an excerpt from the script file:


# wait for lock to be cleared
wait_lock()
{
    # How many times to try for lock clearing
    LOCK_TRIES=720

    # Time to wait
    TRY_TIME=5

    # current try
    try=0

    while [ $try -le $LOCK_TRIES ]
    do
        if [ ! -f $LOCK_LOCATION ]
        then
            # success
            return
        else
            if [ "$PLATFORM" != "NT" ]
            then
                kill -0 $PID > /dev/null 2>&1
            else
                ps | grep $PID > /dev/null 2>&1
            fi
            if [ $? -ne 0 ]
            then
                echo "$progname: \c" >&2
                GetText $TEXTDOMAIN "Notice: Unable to locate process id" >&2
                echo "" >&2
                GetText $TEXTDOMAIN "Info: Station may have died prematurely" >&2
                echo "" >&2
                rm $PID_LOCATION > /dev/null 2>&1
                rm $LOCK_LOCATION > /dev/null 2>&1
                break
            fi
        fi

        sleep $TRY_TIME
        try=`expr $try + 1`

    done

    # If you get here, it is an error. Stop the JVM and exit this shell.
    do_stop
    echo "$progname: \c" >&2
}
		.
		.
		.


	    LOCK_LOCATION=$INSTALL_LOCATION/var/opt/SUNWesm/etc/.lock_file
            
            	.
            	.
            
            > $LOCK_LOCATION

            eval "$COMMAND &"
            PID=$!
            if [ x$PID_LOCATION != x ]
            then
                echo $! > $PID_LOCATION
            fi

            # wait for lock file to be cleared by stations
            wait_lock



And the Java method that removes the file (getLockFile() is a method that
returns the value of the filename and needs to be $LOCK_LOCATION.


  
    /**  remove the lock file
     *
     *  @exception SecurityException thrown when unable to remove the
     *          file because the SecurityManager prevents it.
     */
    private void removeLockFile () throws SecurityException
    {
        File lockF = new File (getLockFile());

        boolean deleted = lockF.delete ();
    }
      

Arieh
--
 Arieh Markel		                Sun Microsystems Inc.
 Network Storage                        500 Eldorado Blvd. MS UBRM11-194
 e-mail: arieh.markel@sun.COM           Broomfield, CO 80021
 Let's go Panthers !!!!                 Phone: (303) 272-8547 x78547
 (e-mail me with subject SEND PUBLIC KEY to get public key)


Mime
View raw message