Maven exec plugin termination

57 Views Asked by At

I am using maven to build and execute a lengthy java user program in an ADOS pipeline using the exec plugin. As the user program requires a lot of memory, I use the exec:exec variant to start its own JVM with a parameter increasing the maximum heap size, all working fine. My pom.xml:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>3.1.0</version>
    <executions>
        <execution>          
            <goals>
                <goal>exec</goal>
            </goals>
        </execution>
    </executions>        
    <configuration>
        <executable>java</executable>
        <arguments>
            <argument>-Xmx12g</argument>
            <argument>-classpath</argument>                        
            <classpath/>
            <argument>my.class</argument>
            <argument>some CLI argument</argument>                   
        </arguments>
    </configuration>               
</plugin>

The problem is terminating this. I am starting maven via a powershell script which builds and runs everything, again fine. As I said, it's a lengthy program, so I might want to terminate it. In ADOS, this works; when calling the script from a shell, maven is terminated, but the JVM running the user program (started by maven exec:exec) is not. In the process explorer I can see that while maven is running, the JVM/user program runs as a child process of JVM/Maven: enter image description here When terminating maven via ctrl-c, the JVM/user program becomes an independent process: enter image description here Now I wonder: why doesn't the user program stop when maven is terminated? I have tried fooling around with the asynchronous options of the exec plugin to no avail. Also: what magic does ADOS use to terminate the program? I know I could always script a termination using the user programs PID, but that seems rather like an overkill.

1

There are 1 best solutions below

0
wade zhou - MSFT On

DevOps will send a termination signal to all processes started by the pipeline, not just the parent process. This is why your Java program is also terminated in devops. You can check detail commands in the pipeline log.

Also, there is no method/api exposed to public from DevOps side.

To achieve the same on local, it's recommended to send a termination signal to the PID when you want to stop the program, it's may not ideal but is the simplest way.