Skip to content

Commit

Permalink
Jenkins should terminate cleanly on SIGTERM (jenkinsci#6230)
Browse files Browse the repository at this point in the history
(cherry picked from commit 1a42044)
  • Loading branch information
basil authored and MarkEWaite committed Mar 4, 2022
1 parent 256d373 commit 3097bb6
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions core/src/main/java/hudson/lifecycle/Lifecycle.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,19 @@
public abstract class Lifecycle implements ExtensionPoint {
private static Lifecycle INSTANCE = null;

public Lifecycle() {
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
Jenkins jenkins = Jenkins.getInstanceOrNull();
if (jenkins != null) {
try {
jenkins.cleanUp();
} catch (Throwable t) {
LOGGER.log(Level.SEVERE, "Failed to clean up. Shutdown will continue.", t);
}
}
}));
}

/**
* Gets the singleton instance.
*
Expand Down

0 comments on commit 3097bb6

Please sign in to comment.