How to detach a Script started Process from Bamboo

Hi,


i`am trying to run a detached shell script from Bamboo on a Windows XP Box. Server Version is 3.3.2 and i`am running a standalone Client jar.

Reproduce with a Script Job with the simple Inline Script (also tested with a called script from the local machine) which does:

START "test" /Min cmd

This spawns a detached local command shell. But Bamboo stalls after starting and you have to close the shell to end the build plan sucessful. This seems to be not the proper behaviour.

1 answer

1 accepted

This widget could not be displayed.

After some more reading into the Details of Java`s System Exec Mechanism i`ve come to the following solution to the matter (inspirend from the Hudson Wiki):

The reason this problem happens is because of file descriptor leak and how they are inherited from one process to another. Java processes and their child process are connected by three pipes (stdin/stdout/stderr.) This allows for capturing the output from the child process. Since the child process may write a lot of data to the pipe and quit immediately after that, the Parent needs to make sure that it drained the pipes before it considers the child to be ready. Usually this is archived by waiting for EOF or null on the reader.

When a process terminates for whatever reasons, the operating system closes all the file descriptors it owned. So even if the child process didn't close stdout/stderr, the parent Process will nevertheless get EOF.

The complication happens when those file descriptors are inherited to other processes. Let's say the child process forks another process to the background. The background process (AKA daemon) inherits all the file descriptors of the parent, including the writing side of the stdout/stderr pipes that connect the child process and the parent Java Process. If the daemon forgets to close them, the Parent won't get EOF for pipes even when the child process exits, because daemon still have those descriptors open. That's how this problem happens.

A good daemon program closes all file descriptors to avoid problems like this, but often there are bad ones that don't follow the rule.

A possible solution to still fork Deamon`s is to use Baseline operating System Mechanisms.

From Windows one can abuse at with Ant`s exec Task:

<tstamp>
<format property="after_1_min" pattern="HH:mm" offset="1" unit="minute"/>
</tstamp>

<exec executable="at">
<arg value="${after_1_min}" />
<arg value="/interactive" />
<arg value="${jboss.home}\bin\run.bat" />
</exec>
This will run JBOSS after one Minute trough at scheduling AND end the Build with succes.

Another possible solution is SCHTASK.

Unix Users shall aquire http://software.clapper.org/daemonize/ which should be sufficient.

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Tuesday in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

300 views 1 4
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you