mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-13 20:12:14 +00:00
Fix [JENKINS-34281] by running shutdown as system user
Replicates the key bit of dad9b04422
But does not include the likely-unneeded ACL.SYSTEM change before System.exit(0)
This commit is contained in:
1 parent
4f51944cf1
commit
543b947e79
1 file changed
+19
-13
@@ -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);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user