tags:

views:

55

answers:

3

I want to make a target to restart tomcat6. Right now, I have something like this:

<taskdef name="stop" classname="org.apache.catalina.ant.StopTask" />
<taskdef name="start" classname="org.apache.catalina.ant.StartTask" />

...

<target name="restart" depends="deploy" description="Restart Tomcat" >
    <stop url="${manager}" username="${username}" password="${password}" path="${path}" />
    <start url="${manager}" username="${username}" password="${password}" path="${path}" />
</target>

Can I rely on stop running before start? Or should I make two separate targets, and have 'start' depend on 'stop'?

+1  A: 

Yes, stop will run before start. Of course, making two separate targets allows you to start and stop from ant, which may be individually useful.

Rob Di Marco
+5  A: 

In general you can rely on Ant to execute tasks in order. The <start> is not executed until <stop> completes.

However given the nature of Tomcat and what it means to "stop Tomcat", what the StopTask actually does is something like

  1. Connect to Tomcat's shutdown port and tell Tomcat to gracefully shut down
  2. Once the message is sent, exit

Therefore, StopTask can be expected to complete before Tomcat has completed it's shutdown process - the task merely tells Tomcat to shut down, it does not wait for it to shut down.

You'll need some other mechanism in your script to make sure that you don't try to start a Tomcat instance while another instance on the same port is still in the midst of shutting down (such as sleeping an arbitrary number of seconds).

matt b
+2  A: 

Yes, order of tasks matters, and in your case 'stop' with run before 'start'. However, 'stop tomcat' (the process, not just the task) is not guaranteed to complete before 'start' will get kicked off.

You may want to make 'start' check and wait until tomcat is not running before starting a new instance.

jprusakova