Pretty cool...but wouldn't a sleep 15 work just as well?  Though you
wouldn't be sure tomcat was really down, I guess.

#!/bin/sh

shutdown.sh
sleep 15
startup.sh

John Turner
[EMAIL PROTECTED]


-----Original Message-----
From: Tim Funk [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, July 17, 2002 9:29 AM
To: Tomcat Users List
Cc: Aleksi Kallio
Subject: Re: How to do stop-start fast?


Something like this may work (just a quick hack so there may be typos)

--start cut here for script
#!/bin/sh
###################################
# restart.sh
# restarts tomcat
# usage: restart.sh ip port
#    ip   - The ip address (or *)
#    port - Which tomcat listens on shutdown
#
#  eg: restart.sh '*' 8005
#      restart.sh 127.0.0.1  8005
#      restart.sh 192.168.0.100  8005
#      restart.sh 207.46.230.218  8005
###################################


#######################################
# Function to check it tomcat is running
# I run wacky UNIX flavor so you netstat
# may differ from mine
# side effect: sets variable IS_RUNNING
# to signify tomcat is listening on port
#######################################
TC_check()
{
   Q="$ADDRESS.$PORT"
   # Grep wants tcp connection that are Listening on the port/address
   IS_RUNNING=`netstat -an|egrep '^tcp'|grep LISTEN|grep "$Q"|wc -l`
}


###################################
# First - is there a TOMCAT_HOME
# so I can call shutdown?

if test "$TOMCAT_HOME" = "" ; then
   echo "TOMCAT_HOME not defined!"
   exit 2
fi

###################################
# Now check the incoming args
ADDRESS=$1
PORT=$2

if test "$ADDRESS" = "" ; then
   echo "In valid arg - no address given!"
   exit 2
fi

if test "$PORT" = "" ; then
   echo "In valid arg - no port given!"
   exit 2
fi


###################################
# Now for the fun
TC_check
if [ IS_RUNNING -eq 1 ] ; then
   echo "Its running - let's shutdown"
   $TOMCAT_HOME/bin/shutdown.sh
   TC_check
fi


while [ IS_RUNNING -eq 1 ] ; do
   echo "Still running"
   sleep 1
   TC_check
done

echo "Now startup ..."
$TOMCAT_HOME/bin/startup.sh
######################################################################
# End of script
######################################################################

Aleksi Kallio wrote:
> Thanks for your fast reply! The netstat alternative seems reasonable. 
> I'm quite new to Unix (server is running Red Hat Linux, shell is csh) 
> and have problems implementing the script.
> 
> Getting the netstat listing and grepping it is no problem, but how I can 
> loop in a shell script while "netstat -l | grep '8442'" returns 
> something ie. socket is alive (8442 is the port number)?
> 
>> You have a few alternatives:
>> 1) Kill the java process and then you can run startup.sh immediatetly
>> 2) Write a wrapper script which calls shutdown.sh, then does one of 
>> the following to verify tomcat is shutdown before calling startup.sh
>>   a) The process is non-existent
>>   b) The port is no taken (use netstat)
>>   c) Parse catalina.out for the phrase saying tomcat was shutdown
>>
>> -Tim
>>
>>
>> Aleksi Kallio wrote:
>>
>>> I have a script that stops Tomcat (shutdown.sh), does stuff and then
>>> restarts it (startup.sh). Doing stuff doesn't take long enough and
>>> Tomcat refuses to restart because the port is still reserved.
>>>
>>> Removing the restart from script and waiting a few secs after running
>>> the script, then restarting manually, works. It is just a bit
>>> frustrating. Also if a restart too early, Tomcat fails to start and
>>> produces a process that has to be killed by hand and it's also 
>>> frustrating.
>>>
>>> How to check if Tomcat is stopped properly?
>>>
>>>  
>>
>>
>>
>>
>> -- 
>> To unsubscribe, e-mail:   
>> <mailto:[EMAIL PROTECTED]>
>> For additional commands, e-mail: 
>> <mailto:[EMAIL PROTECTED]>
> 
> 
> 
> 
> 
> 



--
To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to