Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Ant, does the order of tasks inside a target matter?

Tags:

java

tomcat

ant

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'?

like image 603
Matthew Avatar asked Feb 26 '23 19:02

Matthew


1 Answers

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).

like image 78
matt b Avatar answered Mar 01 '23 09:03

matt b