我们使用NAnt来停止服务,替换文件并开始备份。
<echo message="Waiting for Service to stop."/>
<property name="stopWait" value="360" />
<call target="stopServiceWait" />
...在块下面调用
<!--Waits specified number of seconds or until service is stopped.-->
<target name="stopServiceWait">
<if test="${int::parse(stopWait) > 0}">
<echo message="Stopping Service... Waiting ${stopWait} more seconds..."/>
<property name="stopWait" value="${int::parse(stopWait) - 1}" />
<property name="isStopped" value="${service::is-stopped(bf.serviceName, bf.serverName)}" />
<echo message="isStopped - ${isStopped}"/>
<if test="${isStopped == 'False'}">
<sleep seconds="1" />
<echo message="Service is still not stopped"/>
<call target="stopServiceWait" />
</if>
</if>
</target>
然而,在停止服务后,该过程通常会持续运行几秒钟,阻止文件。所以我们现在再等一会儿:
<!--Wait another 60 sec.-->
<echo message="Sleeping additional 60 seconds to ensure that process shuts down after stop."/>
<sleep seconds="60" />
通常不需要等待很长时间,只需延长停机时间,或者有时不够,并且必须重新启动部署。
问题: 有没有办法从NANT检查是否存在具有特定名称的进程?