NAnt - Check if process exists

Viewed 105

We use NAnt to stop the service, replace the files and start it backup.

<echo message="Waiting for Service to stop."/>
<property name="stopWait" value="360" />
<call target="stopServiceWait" />

... which calls below block

<!--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>

However after stopping the service the process often continues running for quite a few seconds, blocking the files. So we just wait some more time right now:

<!--Wait another 60 sec.-->
<echo message="Sleeping additional 60 seconds to ensure that process shuts down after stop."/>
<sleep seconds="60" />

Often long wait is not necessary and just extends outage, or sometimes it is not enough and the deployment has to be restarted.

Question: Is there a way to check from NANT if the process with the certain name exists?

0 Answers
Related