Skip to content

Commit

Permalink
Add TERM handling
Browse files Browse the repository at this point in the history
This is useful to gracefully stop the Jenkins swarm process, for example
when running in Kubernetes in conjunction with a preStop lifecycle hook.

Signed-off-by: Gavin Williams <[email protected]>
  • Loading branch information
fatmcgav authored and Gavin Williams committed Oct 13, 2021
1 parent 86fb969 commit 167e22a
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions client/src/main/java/hudson/plugins/swarm/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import org.kohsuke.args4j.spi.FieldSetter;
import org.kohsuke.args4j.spi.OptionHandler;

import sun.misc.Signal;
import sun.misc.SignalHandler;
import oshi.SystemInfo;
import oshi.software.os.OSProcess;

Expand Down Expand Up @@ -187,6 +189,14 @@ private static void validateOptions(Options options) {
*/
static void run(SwarmClient swarmClient, Options options, String... args)
throws InterruptedException {

Signal.handle(new Signal("TERM"), new SignalHandler() {
public void handle(Signal sig) {
logger.info("Exiting...");
swarmClient.exitWithStatus(0);
}
});

logger.info("Connecting to Jenkins controller");
URL url = swarmClient.getUrl();

Expand Down

0 comments on commit 167e22a

Please sign in to comment.