Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #2280 from svanoort/fix-shutdown-permissions-issue-J…
…ENKINS-34281-mk3

[FIX JENKINS-34281] Run shutdown as system user
  • Loading branch information
daniel-beck committed Apr 22, 2016
2 parents 5d90f81 + 543b947 commit 84698df
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 84698df

Please sign in to comment.