Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to detach a Script started Process from Bamboo

Christian Schneider November 9, 2011

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

1 vote
Answer accepted
Christian Schneider November 10, 2011

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
TAGS
AUG Leaders

Atlassian Community Events