Skip to content

Commit

Permalink
Jenkins should terminate cleanly on SIGTERM (#6230)
Browse files Browse the repository at this point in the history
  • Loading branch information
basil committed Jan 31, 2022
1 parent 405e977 commit 1a42044
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 @@ -54,6 +54,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 1a42044

Please sign in to comment.