Agent plugin - orphan process management

Our test process involves:

1)  Building an ear
2)  Deploying an ear to jboss app server
3)  Starting app server
4)  Run tests
5)  Shutdown jboss

I think this is a pretty common use case.   Occasionally as we develop, me mess things up so that JBoss does not correctly startup.   A side effect of that is that we do not shut it down correctly.
When the next build on that agent happens, jboss is still "running" and holding onto some ports causing the subsequent runs to fail.

We currently handle this in our build scripts with os specific  (<exec cmd="kill" for windows and shell script on unix side) commands.

In looking through the open api i can see some classes related to process management.

Is it possible to leverage Teamcity openapi in order to manage these processes via a plugin?

For example, if I wrote an agent plugin and listened on a build finished, is there a mechansim for killing any created processes?  If so, can you point me in the right direction?

0
7 comments

We do not provide open API for processes terminator. But you may try using it from processeTerminator.jar

To kill processes call ProcessTreeTerminator.kill method. This method will kill all child processes of build agent.
You may supply non-default ProcessFilter to skip some child processes running under build agent.

Thanks!

0
Avatar
Permanently deleted user

I'll experiment with that and see how it works.

Thanks!

0
Avatar
Permanently deleted user

So what would sample code for this look like?   

The processtreeterminator kill method takes a processfilter.    Is there a class which implements a processfilter which I can instantiate?
Also, can i instantiate the processtreeterminator as I have show below?


@Override
public void buildStarted(AgentRunningBuild runningBuild) {

     LOG.info("IN BUILD STARTED");


    ProcessFilter filter = new ProcessFilter();  //i can't instantiate this type
    ProcessTreeTerminator.kill(filter);
    super.buildStarted(runningBuild);
}

0

ProcessFilter is interface with default implementation ProcessFilter.MATCH_ALL.

I would recommend you killing all processes on the build finish:

public class Killer extends AgentLifeCycleAdapter{
  @Override
  public void buildFinished(@NotNull final BuildFinishedStatus buildStatus) {
    ProcessTreeTerminator.kill(ProcessFilter.MATCH_ALL);
  }
}

I would recommend you to create special system property in build configuration that enables this logic.
You may override buildStarted event and check weather property is set.

0
Avatar
Permanently deleted user

Thank you for your help.

That works very well for in line processes and I plan to take advantage of it.

Does teamcity do any monitoring of spawned processes?

0

No it does not. Honestly, we thought about adding some OS specific hooks to process creation.

Our current implementation builds processes tree. It is able to kill all sub processes of the build agent process.
This technique works for all cases with the following exception. Say there is three processes: A,B,C.
Say B was started by A, C was started by B. We have processes tree A -> B -> C.
Process tree is broken if process B has exited and left process C running. For that case build agent
processes terminator will leave process C running.

It is possible to create processes monitoring using ProcessesTerminator. But, for now there is no API to
kill a process having it's ID. To list all child processes of a build agent you may use ProcessesTreeTerminator.getChildProcesses

Let me know if you need to extend ProcessTreeTerminator API in some way.

Thanks!

0
Avatar
Permanently deleted user

Thanks for the info.  That gives me a much better idea of how things are working under the covers.
I have no need to extend it any further as of now.

0

Please sign in to leave a comment.