Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save atsuteru/5781161 to your computer and use it in GitHub Desktop.
Save atsuteru/5781161 to your computer and use it in GitHub Desktop.

build.xmlに貼り付けます。

<!-- Tomcat停止&停止確認タスク -->
<target name="application-service-stop">
  <echo message="Tomcatアプリケーションを停止しています..." />
  <exec executable="${tomcat.cmd.stop}" />
  <echo message="Tomcatアプリケーションの停止コマンドを発行しました。" />
  <antcall target="application-service-check-stop"/>
  <echo message="Tomcatアプリケーションの停止が完了しました。" />
</target>
<target name="application-service-check-stop">
  <echo message="Tomcatのtelnetポート 8005 が解放されるのを待っています..." />
  <waitfor maxwait="5" maxwaitunit="minute" checkevery="3" checkeveryunit="second" timeoutproperty="tomcat.stop.timeout">
    <not>
      <socket server="localhost" port="8005" />
    </not>
  </waitfor>
  <fail message="Tomcatのtelnetポート 8005 が既定時間内に解放されませんでした! (over 5 minute)" if="tomcat.stop.timeout" status="1"/>
  <echo message="Tomcatのtelnetポート 8005 が解放されるのを確認しました." />
</target>

<!-- Tomcat起動&起動確認タスク -->
<target name="application-service-start">
  <echo message="Tomcatアプリケーションを起動しています..." />
  <exec executable="${tomcat.cmd.start}" />
  <echo message="Tomcatアプリケーションの起動コマンドを発行しました。" />
  <antcall target="application-service-check-start"/>
  <echo message="Tomcatアプリケーションの起動が完了しました。" />
</target>
<target name="application-service-check-start" if="server.address">
  <echo message="Tomcatトップページ [http://localhost:8080/MyApplication/] への接続確認を行っています..." />
  <waitfor maxwait="5" maxwaitunit="minute" checkevery="3" checkeveryunit="second" timeoutproperty="tomcat.start.timeout">
    <http url="http://localhost:8080/MyApplication/" />
  </waitfor>
  <fail message="Tomcatトップページ [http://localhost:8080/MyApplication/] への接続が既定時間内に確認できませんでした! (over 5 minute)" if="tomcat.start.timeout" status="1"/>
  <echo message="Tomcatトップページ [http://localhost:8080/MyApplication/] への接続確認が完了しました." />
</target>

参考:http://ant.apache.org/manual/Tasks/waitfor.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment