public void invokeHudson(boolean restart) { final WebAppController controller = WebAppController.get(); if (initialClassLoader == null) { initialClassLoader = getClass().getClassLoader(); } Class hudsonIsLoadingClass; try { outerClassLoader = new OuterClassLoader(initialClassLoader); hudsonIsLoadingClass = outerClassLoader.loadClass("hudson.util.HudsonIsLoading"); HudsonIsLoading hudsonIsLoading = (HudsonIsLoading) hudsonIsLoadingClass.newInstance(); Class runnableClass = outerClassLoader.loadClass("org.eclipse.hudson.init.InitialRunnable"); Constructor ctor = runnableClass.getDeclaredConstructors()[0]; ctor.setAccessible(true); InitialRunnable initialRunnable = (InitialRunnable) ctor.newInstance(controller, logger, hudsonHomeDir, servletContext, restart); controller.install(hudsonIsLoading); initThread = new Thread(initialRunnable, "hudson initialization thread " + (++highInitThreadNumber)); initThread.setContextClassLoader(outerClassLoader); initThread.start(); } catch (Exception ex) { logger.error("Hudson failed to load!!!", ex); } /** * Above replaces these lines controller.install(new HudsonIsLoading()); * * new Thread("hudson initialization thread") { }.start(); */ }
protected void execute() { File timestampFile = new File(home, ".owner"); long t = timestampFile.lastModified(); if (t != 0 && lastWriteTime != 0 && t != lastWriteTime && !ignore) { try { collidingId = FileUtils.readFileToString(timestampFile); } catch (IOException e) { LOGGER.log(Level.SEVERE, "Failed to read collision file", e); } // we noticed that someone else have updated this file. // switch GUI to display this error. WebAppController.get().install(this); LOGGER.severe("Collision detected. timestamp=" + t + ", expected=" + lastWriteTime); // we need to continue updating this file, so that the other Hudson would notice the problem, too. } try { FileUtils.writeStringToFile(timestampFile, getId()); lastWriteTime = timestampFile.lastModified(); } catch (IOException e) { // if failed to write, err on the safe side and assume things are OK. lastWriteTime = 0; } schedule(); }
@Override public void run() { try { // Creating of the god object performs most of the booting muck Hudson hudson = new Hudson(hudsonHomeDir, servletContext, null, restart); //Now Hudson is fully loaded, reload Hudson Security Manager HudsonSecurityEntitiesHolder.setHudsonSecurityManager(new HudsonSecurityManager(hudsonHomeDir)); // once its done, hook up to stapler and things should be ready to go controller.install(hudson); // trigger the loading of changelogs in the background, // but give the system 10 seconds so that the first page // can be served quickly // Trigger.timer.schedule(new SafeTimerTask() { // public void doRun() { // User.getUnknown().getBuilds(); // } // }, 1000 * 10); } catch (Error e) { logger.error("Failed to initialize Hudson", e); controller.install(new HudsonFailedToLoad(e)); throw e; } catch (Exception e) { logger.error("Failed to initialize Hudson", e); controller.install(new HudsonFailedToLoad(e)); } } }
@Override public void run() { try { HudsonSecurityManager.grantFullControl(); // Wait 'til we have no active executors. doQuietDown(true, 0); // Make sure isQuietingDown is still true. if (isQuietingDown) { WebAppController.get().install(new HudsonIsRestarting()); // give some time for the browser to load the "reloading" page logger.info("Restart in 10 seconds"); Thread.sleep(10000); logger.error(String.format("Restarting VM as requested by %s", exitUser)); for (RestartListener listener : RestartListener.all()) { listener.onRestart(); } lifecycle.restart(); } else { logger.info("Safe-restart mode cancelled"); } } catch (InterruptedException e) { logger.warn("Failed to restart Hudson", e); } catch (IOException e) { logger.warn("Failed to restart Hudson", e); } finally { Hudson.this.safeRestarting = false; } } }.start();
/** * Ignore the problem and go back to using Hudson. */ public void doIgnore(StaplerRequest req, StaplerResponse rsp) throws IOException { ignore = true; WebAppController.get().install(Hudson.getInstance()); rsp.sendRedirect2(req.getContextPath() + '/'); } private static final Logger LOGGER = Logger.getLogger(DoubleLaunchChecker.class.getName());
/** * Reloads the configuration synchronously. */ public void reload() throws IOException, InterruptedException, ReactorException { executeReactor(null, loadTasks()); User.reload(); initLevel = InitMilestone.COMPLETED; WebAppController.get().install(this); }
new URLClassLoader(new URL[0], getClass().getClassLoader()); } catch (SecurityException e) { controller.install(new InsufficientPermissionDetected(e)); return; controller.install(new NoHomeDir(home)); return; controller.install(new IncompatibleVMDetected()); return; ServletResponse.class.getMethod("setCharacterEncoding", String.class); } catch (NoSuchMethodException e) { controller.install(new IncompatibleServletVersionDetected(ServletResponse.class)); return; FileSet.class.getMethod("getDirectoryScanner"); } catch (NoSuchMethodException e) { controller.install(new IncompatibleAntVersionDetected(FileSet.class)); return; controller.install(new AWTProblem(ChartUtil.awtProblemCause)); return; f.delete(); } catch (IOException e) { controller.install(new NoTempDir(e)); return;
/** * Performs a restart. */ public void restart() throws RestartNotSupportedException { final Lifecycle lifecycle = Lifecycle.get(); lifecycle.verifyRestartable(); // verify that Hudson is restartable WebAppController.get().install(new HudsonIsRestarting()); new Thread("restart thread") { final String exitUser = getAuthentication().getName(); @Override public void run() { try { HudsonSecurityManager.grantFullControl(); // give some time for the browser to load the "reloading" page Thread.sleep(5000); logger.error(String.format("Restarting VM as requested by %s", exitUser)); for (RestartListener listener : RestartListener.all()) { listener.onRestart(); } lifecycle.restart(); } catch (InterruptedException e) { logger.warn("Failed to restart Hudson", e); } catch (IOException e) { logger.warn("Failed to restart Hudson", e); } } }.start(); }
/** * Reloads the configuration. */ @CLIMethod(name = "reload-configuration") public synchronized HttpResponse doReload() throws IOException { checkPermission(ADMINISTER); // engage "loading ..." UI and then run the actual task in a separate thread WebAppController.get().install(new HudsonIsLoading()); new Thread("Hudson config reload thread") { @Override public void run() { try { HudsonSecurityManager.grantFullControl(); reload(); } catch (IOException e) { logger.error("Failed to reload Hudson config", e); } catch (ReactorException e) { logger.error("Failed to reload Hudson config", e); } catch (InterruptedException e) { logger.error("Failed to reload Hudson config", e); } } }.start(); return HttpResponses.redirectViaContextPath("/"); }
controller.install(hudson);
WebAppController.get().install(new HudsonIsRestarting());