1

我有一个 Ant 脚本,用于一次在两台不同的机器上部署我的应用程序。使用本地机器我没有问题,但是当涉及到远程机器时,我想检查 Jboss 是否启动。如果它启动了,那么我想将其关闭,但如果它不是,那么什么都不应该做。我试图通过保留<sshexec>as的属性来做到这一点failonerror="on"。当 Jboss 已经关闭并且关闭命令只给出一些错误时,这很有效。但我面临的真正问题是当 Jboss 运行时,当执行关闭命令时,它没有正确关闭并给出了一些错误。正是在这些情况下,我想停止我的构建脚本并让用户知道另一台机器上的 Jboss 有问题,需要查看它。

停止远程 Jboss 的目标代码是

<target name="stopRemoteJboss" description="Stops Remote Instance of Jboss">
        <echo message="Stopping Remote Jboss" />
        <sshexec trust="true" host="${jboss.remote.host}" username="${jboss.remote.username}" password="${jboss.remote.password}" command="${jboss.remote.home}/bin/shutdown.sh -S" port="${jboss.remote.port}"/>
    </target>
4

2 回答 2

1

经过简短的检查,我发现以下内容,也许您可​​以重用/或用作脚本的灵感: http: //shrubbery.homeip.net/c/display/W/Starting+JBoss+with+ANT

您的相关部分似乎是:

<java jvm="@{jdkHome}/bin/java"
      classname="org.jboss.Shutdown" fork="true" failonerror="false" resultproperty="shutdown.rc">
    <arg line="-s jnp://@{bindAddr}:@{jnpPort}"/>
    <classpath>
        <pathelement path="@{jbossInstallDir}/bin/shutdown.jar"/>
        <pathelement path="@{jbossInstallDir}/client/jbossall-client.jar"/>
    </classpath>
</java>
<echo>Shutdown rc = ${shutdown.rc}</echo>
<condition property="shutdown.okay">
    <equals arg1="${shutdown.rc}" arg2="0"/>
</condition>
<fail unless="shutdown.okay" message="Unable to shut down JBoss (maybe it hasn't fully started yet?)."/>
<echo>Waiting for @{bindAddr}:@{jnpPort} to stop listening...</echo>
于 2012-12-04T12:20:14.460 回答
1

为什么不检查远程端口是否处于活动状态?

<project name="demo" default="check">

    <condition property="server.running" value="running" else="not running">
        <socket server="remoteserver" port="80"/>
    </condition>

    <target name="check" description="Print status message">
        <echo message="Web server status: ${server.running}"/>
    </target>

</project>

如果您的 JBoss 实例配置为反向代理,您可以使用替代http 条件来检查 HTTP 响应代码(如果应用服务器已关闭,则为 503“服务不可用”)

于 2012-12-04T21:09:19.663 回答