Discussion:
nohup and Ant question
Z W
2008-01-25 01:20:49 UTC
Permalink
Hi

I have a shell script where in it, it has these lines

nohup ./mdmctl start-t -dep zg &
nohup vmstat 10 > $log_location/vmstat_$1.log &
echo "Wait to come up...sleep for 100 secs"
sleep 100
echo "Starting prstat."
pid=`ps -ef|awk '/'"java -server -XX:CompileThreshold"'/ && !/bash/ {print
$2}'`
echo "pid = $pid"
./test_prstat $pid > $log_location/prstat_$1.log &
echo "pid = $pid"
where mdmctl and test_prstat are additonal separate shell scripts.



When running Ant, its output s


[rexec] Wait to come up...sleep for 100 secs
[rexec] Starting prstat.
[rexec] pid =
[rexec] pid =
[rexec] prstat: illegal argument -- -n
Terminate batch job (Y/N)? y

But when I tried running the shell script directly on a unix shell, it works
just fine,
giving output

# zach_starttest 88770099

Sending output to nohup.out
Waiting for iMDM server to come up...sleep for 100 secs
Sending output to nohup.out


I like to know if there's a way in Ant to detect "Sending output to
nohupout" response from remote unix host
so that my Ant script wouldn't hang on step
[rexec] prstat: illegal argument -- -n

I have to terminate the Ant script on my own.

Thanks
Chuck Holzwarth
2008-01-25 14:39:19 UTC
Permalink
You may have several problems here.
Both nohup commands start asynchronous processes that don't end when the connection is broken and you may end up with zombies running.

Both nohup commands write to nohup.out with the second one probably overwriting the same file. You can do this on Unix/Lunix etc. without a problem. The disk space is not cleared up until the nohup process exits but is not available unless you can access the inode where the file still exists. You can try appending ">> output 2>&1" to the end of the nohup commands to capture all of the output.

If there are zombies, you may be getting more than one line from awk and that may not work well.

It looks like prstat does not like the blank pid. You may want to echo the result of the ps as well as use it to set the pid variable for debugging purposes. Something like:
echo "Getting PS info" >> output 2>&1
ps -ef >> output 2>&1
echo "Applying awk filter" >> output 2>&1
ps -ef | awk '/'"java -server -XX:CompileThreshold"'/ && !/bash/ {print $2}'` >> output 2>&1
pid=`ps -ef|awk '/'"java -server -XX:CompileThreshold"'/ && !/bash/ {print $2}'` 2>&1
This will give

The fact that you are not getting the variable, pid, set is probably the key issue.

If you want to see the output as well as send it to a file, look at the tee command or the script command instead of the ">> output"


Z W <***@gmail.com> wrote: Hi

I have a shell script where in it, it has these lines

nohup ./mdmctl start-t -dep zg &
nohup vmstat 10 > $log_location/vmstat_$1.log &
echo "Wait to come up...sleep for 100 secs"
sleep 100
echo "Starting prstat."
pid=`ps -ef|awk '/'"java -server -XX:CompileThreshold"'/ && !/bash/ {print
$2}'`
echo "pid = $pid"
./test_prstat $pid > $log_location/prstat_$1.log &
echo "pid = $pid"
where mdmctl and test_prstat are additonal separate shell scripts.



When running Ant, its output s


[rexec] Wait to come up...sleep for 100 secs
[rexec] Starting prstat.
[rexec] pid =
[rexec] pid =
[rexec] prstat: illegal argument -- -n
Terminate batch job (Y/N)? y

But when I tried running the shell script directly on a unix shell, it works
just fine,
giving output

# zach_starttest 88770099

Sending output to nohup.out
Waiting for iMDM server to come up...sleep for 100 secs
Sending output to nohup.out


I like to know if there's a way in Ant to detect "Sending output to
nohupout" response from remote unix host
so that my Ant script wouldn't hang on step
[rexec] prstat: illegal argument -- -n

I have to terminate the Ant script on my own.

Thanks



Thank you,
Chuck Holzwarth
(804) 403-3478 (home)
(540) 335-3171 (cell)

---------------------------------
Looking for last minute shopping deals? Find them fast with Yahoo! Search.
Z W
2008-01-25 21:24:46 UTC
Permalink
Hi Chuck
Appreciate your response.
I'm using Ant 1.7 on Windows.
I'm pretty sure it's an ANT issue that doesn't deal well with nohup.

Is there a workaround with Ant. Running the unix script directly, the pid is
found; not a shell script
issue.
Barry Pape
2008-01-28 20:08:55 UTC
Permalink
Sounds similar to the issue I just had. The solution that worked for me
came from here: http://marc.info/?l=ant-user&m=100621497023872&w=2


-----Original Message-----
From: Z W [mailto:***@gmail.com]
Sent: Friday, January 25, 2008 3:25 PM
To: Ant Users List
Subject: Re: nohup and Ant question

Hi Chuck
Appreciate your response.
I'm using Ant 1.7 on Windows.
I'm pretty sure it's an ANT issue that doesn't deal well with nohup.

Is there a workaround with Ant. Running the unix script directly, the
pid is
found; not a shell script
issue.

-----------------------------------------
Confidentiality Notice!
This electronic transmission and any attached documents or other
writings are confidential and are for the sole use of the intended
recipient(s) identified above. This message may contain information
that is privileged, confidential or otherwise protected from
disclosure under applicable law. If the receiver of this
information is not the intended recipient, or the employee, or
agent responsible for delivering the information to the intended
recipient, you are hereby notified that any use, reading,
dissemination, distribution, copying or storage of this information
is strictly prohibited. If you have received this information in
error, please notify the sender by return email and delete the
electronic transmission, including all attachments from your
system.
Z W
2008-01-28 21:23:11 UTC
Permalink
Barry

It's a little complicated for me in that solution.
Do you have a simpler one ?
Will it work for <rexec> as opposed to <exec> ?

Thanks
Barry Pape
2008-01-28 21:53:13 UTC
Permalink
The post on CruiseControl's Confluence maybe easier to follow
(http://confluence.public.thoughtworks.org/display/CC/Running+Servertest
s+with+Ant), but basically you use the script as a wrapper to call
yours. I actually added the 'ANTRUN_OUTPUT' variable to the wrapper
script and just execute an ssh command.

So, 'antRunAsync.sh':
#!/bin/sh
# antRunAsync - Wrapper script to run an executable detached in the
# background from Ant's <exec> task. This works be redirecting stdin,
# stdout and stderr so Ant finds them closed and doesn't wait for the
# program to exit.
#
# usage:
# <exec executable="antRunAsync.sh" failonerror="yes">
# <env key="ANTRUN_NOHUP" value="true" /> <!-- optional -->
# <env key="ANTRUN_OUTPUT" value="output.log" /> <!-- required, may
be /dev/null -->
# <arg value="real executable" />
# </exec>

# If ANTRUN_NOHUP environment variable is set to true/yes/nohup, run
the
# executable prefixed with "nohup" making it immune to logging out.
case "$ANTRUN_NOHUP" in
true|yes|nohup) ANTRUN_NOHUP=nohup ;;
*) unset ANTRUN_NOHUP ;;
esac

# ANTRUN_OUTPUT environment variable must be set to output file name or
# executable can't run detached
ANTRUN_OUTPUT=../my/path/here/nohup.out ### <-- THE ONLY THING I ADDED
if [ -n "$ANTRUN_OUTPUT" ]
then
$ANTRUN_NOHUP $@ </dev/null > "$ANTRUN_OUTPUT" 2>&1 &
exit 0
else
echo "$0: ERROR: variable ANTRUN_OUTPUT must be set to output file
name!"
exit 1
fi

My ant exec:
<exec executable="ssh">
<arg line="${remote.host} ./antRunAsync.sh ./run_app.sh " />
</exec>

And run_app.sh is simply:
cd /path/to/my/app
nohup ./run.sh &


I don't actually know if it works with rexec, I had issues getting rexec
to work and went back to exec.


-----Original Message-----
From: Z W [mailto:***@gmail.com]
Sent: Monday, January 28, 2008 3:23 PM
To: Ant Users List
Subject: Re: nohup and Ant question

Barry

It's a little complicated for me in that solution.
Do you have a simpler one ?
Will it work for <rexec> as opposed to <exec> ?

Thanks
<HTML><BODY><P><hr size=1></P><br>
<P><br>
Confidentiality Notice!<br>
This electronic transmission and any attached documents or other<br>
writings are confidential and are for the sole use of the intended<br>
recipient(s) identified above. This message may contain information<br>
that is privileged, confidential or otherwise protected from<br>
disclosure under applicable law. If the receiver of this<br>
information is not the intended recipient, or the employee, or<br>
agent responsible for delivering the information to the intended<br>
recipient, you are hereby notified that any use, reading,<br>
dissemination, distribution, copying or storage of this information<br>
is strictly prohibited. If you have received this information in<br>
error, please notify the sender by return email and delete the<br>
electronic transmission, including all attachments from your<br>
system.<br>
<P></BODY></HTML>
dfreis
2011-01-11 09:55:13 UTC
Permalink
had the same issue with nohup and a forked java task. The problem was that
the input of the forked java task was still taken from the console and the
java task was hanging.
Adding input="/dev/null" to my java task solved the problem!
--
View this message in context: http://ant.1045680.n5.nabble.com/nohup-and-Ant-question-tp1350407p3336165.html
Sent from the Ant - Users mailing list archive at Nabble.com.
Loading...