How to detach a Script started Process from Bamboo


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

1 vote
Accepted answer

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:

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

<exec executable="at">
<arg value="${after_1_min}" />
<arg value="/interactive" />
<arg value="${jboss.home}\bin\run.bat" />
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 which should be sufficient.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published yesterday in Statuspage

194 years of downtime: looking back on incident data from 2018

Statuspage customers logged more than 194 years of collective incidents in 2018. That’s a whopping 87% increase from the  104 years logged in 2017 , and we aren’t even through December yet....

36 views 1 5
Read article

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