How to kill running exec task in ANT - ant

I'm trying to start a weblogic server using ant exec command,after the operation triggers the exec process creates a child process, i wish to kill the parent process and keep alive the child process.
My code below
<project name="startserver" default="start" basedir=".">
<target name="start">
<exec dir="C:\bea\user_projects\domains\devtest"
executable="cmd"
failonerror="true">
<arg value="/c"/>
<arg value="startWebLogic.cmd"/>
</exec>
</target>
</project>
this code starts server and my application is also up, problem is that ant script is still running & moreover it doesn't exit as shown below
how can i exit from the exec and kill the parent process, as a workaround i tried using
timeout
attribute of exec task, but it kills both parent and child process, how can i achieve this so that ANT exits and also server keeps running in the background.

Try the spawn="true" attribute of the exec task. It should do what you are looking for. But beware of the implications for input/output handling (see link).

When you set spawn="true" for exec tag, the child process runs in the the background even if current process ends execution. In your case instead of cmd, use startweblogic.cmd directly as exec command.

Related

Running an OS command using apache-ant to IIS config

I'm trying to create an ANT script which amongst other things will configure IIS.
To do this, trying to harness the appcmd tool. However getting a strange error. The appcmd command runs fine outside of the ant script, but fails within.
I'm using the exec task to kick it all off :
<exec dir="C:\\Windows\\System32\\inetsrv\\"
executable="C:\\Windows\\System32\\inetsrv\\appcmd.exe" output="d:\out.txt">
<arg value="appcmd set config /section:isapiCgiRestriction /+"
[path='${appian_home}\\jakarta\\ISAPI\\isapi_redirect.dll',
description='Jakarta',allowed='True']"" />
</exec>
The output trapped via ANT is :
Object 'APPCMD SET CONFIG /SECTION:ISAPICGIRESTRICTION /+?
[PATH='D:\PTMP2\APPIAN17\\JAKARTA\\ISAPI\\ISAPI_REDIRECT.DLL',
DESCRIPTION='JAKARTA',ALLOWED='TRUE']' is not supported.
Run 'appcmd.exe /?' to display supported objects.
However when I run
If I c&p that command to the dos prompt it will happily run :
C:\Windows\System32\inetsrv>appcmd set config /section:isapiCgiRestriction
/+"[path='d:\ptmp2\appian17\\jakarta5\\ISAPI\\isapi_redirect.dll',descripti
on='Jakarta',allowed='True']"
Applied configuration changes to section
"system.webServer/security/isapiCgiRestriction" for
"MACHINE/WEBROOT/APPHOST" at configuration commit path "M
ACHINE/WEBROOT/APPHOST"
Needs to escaped single quote as well.
Also changed path separate to /
Use below:
<exec executable="cmd.exe" dir="C:/Windows/System32/inetsrv" failonerror="true">
<arg line="/c appcmd set config /section:isapiCgiRestriction /+"[path=&apos;${appian_home}/jakarta/ISAPI/isapi_redirect.dll&apos;,description=&apos;Jakarta&apos;,allowed=&apos;True&apos;]""/>
</exec>

Ant task hangs due to suspected permissions issue

I have a STAF job which kicks off an Ant script, all run under a functional ID. The ant script does basic 'init' tasks which work fine, and then hangs on one of the following tasks: delete, mkdir, or junit, depending on how much muddling I do in the file system.
<target name="run.nightly.tests" depends="init">
<delete dir="/path/results/latestDate" />
<mkdir dir="/path/results/latestDate" />
<chmod perm="777" dir="/path/results/latestDate" />
<junit printsummary="on" fork="no">
<!-- typical classpath/tests setup snipped -->
</junit>
</target>
I am able to sudo to this functional ID and run the corresponding commands from a shell just fine (ex: rm -rf /path/results/latestDate). Clearly something is different about running in the Ant environment, under the functional id. (In fact, I can run the script just fine with my own id)
/path/results has 777 permissions before my script runs, and when /path/results/latestDate exists it is owned by the same functional id w/ 777 permissions.
STAF launches this script:
export ANT_HOME=/opt/apache-ant-1.8.2
#This entire directory tree and jar files are world r+x
LIB_DIR=/home/afreed/automation/dependencies/mail
ant -debug -verbose -buildfile nightlyTest.xml -lib ${LIB_DIR}/mail.jar:${LIB_DIR}/activation.jar
I would understand if Ant would fail on any of these tasks with a permissions error but I cannot understand why it would hang.
I would like help either a) determining why there is a hang or b) how to convert the hang to a hard failure
Solved, the Ant script was hanging on an exec command that was waiting for input from STDIN. (Execution had continued past that point because it was launched with 'spawn' attribute.) When I removed this 'exec' task from my 'init' target, the Ant script ran as expected.
<!-- hanging task in init-->
<exec executable="blah.sh" spawn="true">

Run batch command after ant build

I'm trying to create a batch file that automates an annoying build process. The key part that's tripping me up is when a command starts a process that takes over input from the keyboard.
Basically, I run something along the lines of ant -f build-rmi.xml rmiregistry, which builds and runs the rmiregistry. After this is completed i need to run another build, but I can't figure out how to launch another command after the ant build is finished executing
I don't have write access to any of the ant files.
Create a new ANT build script run-both.xml
Add an Import in run-both.xml to get the original script.
Create a new target in run-both.xml, say "runbatch".Use ANT exec task to call the DOS command from this target
<project name="run-both" default="runbatch">
<import file="${path_to_rmi}/build-rmi.xml"/>
<target name="runbatch" depends="rmiregistry">
<exec executable="cmd">
<arg value="/c"/>
<arg value="echo hello Matt"/>
</exec>
</target>
</project>
On the command prompt
ant -f run-both.xml
use command call , the batch script file will not stop after run ant command
call ant

How can I redirect ant exec task output to both a file and stdout?

I am using the ant (1.8.2) exec task to start a child process. I need the output of the child process to be shown as part of the normal ant console output, but also be captured in a file.
You need the redirector
Since Ant 1.6.3 it has an option called alwayslog.
Use it like this:
<exec executable="mycommand">
<redirector output="myfile.txt" alwayslog="true"/>
</exec>

Ant build shutdown - Ctrl C

I have a set of ant tasks that I use to run my test suite, occasionally one of those tests will freeze and my entire test suite will hang. I added a shutdown handler so when I hit Ctrl+C ant will shutdown gracefully and give me a report with the final test marked as not run. (This is important because these are integration tests and can run for hours) This works great except for on Windows where my shutdown hook is not being called. Is there a way I can get ant to respond to any kind of input and do a graceful shutdown?
It seems this is a long-running known issue.
The problem is that on Windows the Ant Ctrl+C is, as you have observed, not propagated to the child VMs. Things you might consider:
Break up the test into smaller pieces and use a timeout to kill anything that hangs. This will limit the data lost to the one test that hangs.
In your test run, add a 'listener' thread that waits for a shutdown 'signal' (perhaps the presence of a flag file) and arrange for that signal to be set by Ant, on command from the console, if hang is detected.
This appears complex, but might be worth a shot. You'd need to combine the Ant parallel and input tasks to run the tests in one thread, and wait for input from the console in a second thread. When abort is chosen, the signal file is written, this is detected in the test run 'listener', causing it to terminate. Any other input would lead to clean termination of the run. The problem with this is that, if the test completes successfully, you're left with Ant waiting for user input, but you could put an overall timeout in place for that. (I've not given an example of how the test run code might detect the signal file.)
Psuedo-Ant:
<property name="signal.abort" value="stop.txt" />
<target name="runner">
<delete file="${signal.abort}" />
<parallel timeout="86400000">
<sequential>
<!-- run tests here -->
</sequential>
<sequential>
<input validargs="y,n"
message="Abort the test (y/n)?"
addproperty="abort.test" />
<condition property="do.abort">
<equals arg1="y" arg2="${abort.test}"/>
</condition>
<ant target="terminator" />
</sequential>
</parallel>
</target>
<target name="terminator" if="do.abort">
<echo message="abort" file="${signal.abort}" />
</target>

Resources