Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix [JENKINS-34281] by running shutdown as system user
Replicates the key bit of dad9b04
But does not include the likely-unneeded ACL.SYSTEM change before System.exit(0)
  • Loading branch information
svanoort committed Apr 20, 2016
1 parent 4f51944 commit 543b947
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions core/src/main/java/hudson/WebAppMain.java
Expand Up @@ -27,6 +27,7 @@
import com.thoughtworks.xstream.core.JVM;
import com.trilead.ssh2.util.IOUtils;
import hudson.model.Hudson;
import hudson.security.ACL;
import hudson.util.BootFailure;
import jenkins.model.Jenkins;
import hudson.util.HudsonIsLoading;
Expand Down Expand Up @@ -244,7 +245,7 @@ public void run() {
};
initThread.start();
} catch (BootFailure e) {
e.publish(context,home);
e.publish(context, home);
} catch (Error | RuntimeException e) {
LOGGER.log(SEVERE, "Failed to initialize Jenkins",e);
throw e;
Expand Down Expand Up @@ -364,19 +365,24 @@ public FileAndDescription getHomeDir(ServletContextEvent event) {

public void contextDestroyed(ServletContextEvent event) {
try {
terminated = true;
Jenkins instance = Jenkins.getInstanceOrNull();
if(instance!=null)
instance.cleanUp();
Thread t = initThread;
if (t != null && t.isAlive()) {
LOGGER.log(Level.INFO, "Shutting down a Jenkins instance that was still starting up", new Throwable("reason"));
t.interrupt();
}
ACL.impersonate(ACL.SYSTEM, new Runnable() {
@Override
public void run() {
terminated = true;
Jenkins instance = Jenkins.getInstanceOrNull();
if (instance != null)
instance.cleanUp();
Thread t = initThread;
if (t != null && t.isAlive()) {
LOGGER.log(Level.INFO, "Shutting down a Jenkins instance that was still starting up", new Throwable("reason"));
t.interrupt();
}

// Logger is in the system classloader, so if we don't do this
// the whole web app will never be undepoyed.
Logger.getLogger("").removeHandler(handler);
// Logger is in the system classloader, so if we don't do this
// the whole web app will never be undepoyed.
Logger.getLogger("").removeHandler(handler);
}
});
} finally {
JenkinsJVMAccess._setJenkinsJVM(false);
}
Expand Down

0 comments on commit 543b947

Please sign in to comment.