提交 84698df8 编写于 作者: D Daniel Beck

Merge pull request #2280 from svanoort/fix-shutdown-permissions-issue-JENKINS-34281-mk3

[FIX JENKINS-34281] Run shutdown as system user
......@@ -27,6 +27,7 @@ import com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider
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;
......@@ -244,7 +245,7 @@ public class WebAppMain implements ServletContextListener {
};
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;
......@@ -364,19 +365,24 @@ public class WebAppMain implements ServletContextListener {
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);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册