From 40e9dd70f41ee2e5e9def99e4a8e0754abff4f43 Mon Sep 17 00:00:00 2001 From: Ulli Hafner Date: Fri, 6 May 2011 16:23:52 +0200 Subject: [PATCH] [FIXED JENKINS-5047] Restart button now adds a restart action to the queue instead of restarting immediately. --- .../main/java/hudson/model/UpdateCenter.java | 52 +++++++++++++++++-- .../UpdateCenter/RestartJenkinsJob/row.jelly | 31 +++++++++++ .../RestartJenkinsJob/row_de.properties | 23 ++++++++ .../hudson/model/UpdateCenter/index.jelly | 4 +- .../model/UpdateCenter/index_de.properties | 10 ++-- 5 files changed, 108 insertions(+), 12 deletions(-) create mode 100644 core/src/main/resources/hudson/model/UpdateCenter/RestartJenkinsJob/row.jelly create mode 100644 core/src/main/resources/hudson/model/UpdateCenter/RestartJenkinsJob/row_de.properties diff --git a/core/src/main/java/hudson/model/UpdateCenter.java b/core/src/main/java/hudson/model/UpdateCenter.java index 00b3fe70d5..cef399d748 100644 --- a/core/src/main/java/hudson/model/UpdateCenter.java +++ b/core/src/main/java/hudson/model/UpdateCenter.java @@ -1,18 +1,18 @@ /* * The MIT License - * + * * Copyright (c) 2004-2010, Sun Microsystems, Inc., Kohsuke Kawaguchi, Yahoo! Inc., Seiji Sogabe - * + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. - * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -35,6 +35,7 @@ import hudson.XmlFile; import static hudson.init.InitMilestone.PLUGINS_STARTED; import hudson.init.Initializer; import hudson.lifecycle.Lifecycle; +import hudson.lifecycle.RestartNotSupportedException; import hudson.model.UpdateSite.Data; import hudson.model.UpdateSite.Plugin; import hudson.model.listeners.SaveableListener; @@ -46,6 +47,7 @@ import hudson.util.XStream2; import org.acegisecurity.Authentication; import org.apache.commons.io.input.CountingInputStream; import org.apache.commons.io.output.NullOutputStream; +import org.kohsuke.stapler.StaplerRequest; import org.kohsuke.stapler.StaplerResponse; import javax.net.ssl.SSLHandshakeException; @@ -87,7 +89,7 @@ import org.acegisecurity.context.SecurityContextHolder; * and plugins, and to use alternate strategies for downloading, installing * and updating components. See the Javadocs for {@link UpdateCenterConfiguration} * for more information. - * + * * @author Kohsuke Kawaguchi * @since 1.220 */ @@ -284,6 +286,16 @@ public class UpdateCenter extends AbstractModelObject implements Saveable { rsp.sendRedirect2("."); } + /** + * Schedules a Jenkins restart. + */ + public void doSafeRestart(StaplerRequest request, StaplerResponse response) throws IOException, ServletException { + Hudson.getInstance().checkPermission(Hudson.ADMINISTER); + addJob(new RestartJenkinsJob(getCoreSource())); + LOGGER.info("Scheduling Jenkings reboot"); + response.sendRedirect2("."); + } + /** * Returns true if backup of jenkins.war exists on the hard drive */ @@ -308,6 +320,18 @@ public class UpdateCenter extends AbstractModelObject implements Saveable { rsp.sendRedirect2("."); } + /** + * Performs hudson downgrade. + */ + public void doRestart(StaplerResponse rsp) throws IOException, ServletException { + Hudson.getInstance().checkPermission(Hudson.ADMINISTER); + HudsonDowngradeJob job = new HudsonDowngradeJob(getCoreSource(), Hudson.getAuthentication()); + LOGGER.info("Scheduling the core downgrade"); + + addJob(job); + rsp.sendRedirect2("."); + } + /** * Returns String with version of backup .war file, * if the file does not exists returns null @@ -684,6 +708,24 @@ public class UpdateCenter extends AbstractModelObject implements Saveable { } } + /** + * Restarts jenkins. + */ + public class RestartJenkinsJob extends UpdateCenterJob { + public RestartJenkinsJob(UpdateSite site) { + super(site); + } + + public void run() { + try { + Hudson.getInstance().safeRestart(); + } + catch (RestartNotSupportedException exception) { + // ignore if restart is not allowed + } + } + } + /** * Tests the internet connectivity. */ diff --git a/core/src/main/resources/hudson/model/UpdateCenter/RestartJenkinsJob/row.jelly b/core/src/main/resources/hudson/model/UpdateCenter/RestartJenkinsJob/row.jelly new file mode 100644 index 0000000000..84a0fb34a9 --- /dev/null +++ b/core/src/main/resources/hudson/model/UpdateCenter/RestartJenkinsJob/row.jelly @@ -0,0 +1,31 @@ + + + + + + ${%Restarting Jenkins} + + + diff --git a/core/src/main/resources/hudson/model/UpdateCenter/RestartJenkinsJob/row_de.properties b/core/src/main/resources/hudson/model/UpdateCenter/RestartJenkinsJob/row_de.properties new file mode 100644 index 0000000000..9e491a7e16 --- /dev/null +++ b/core/src/main/resources/hudson/model/UpdateCenter/RestartJenkinsJob/row_de.properties @@ -0,0 +1,23 @@ +# The MIT License +# +# Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi, Ulli Hafner +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. + +Restarting\ Jenkins=Jenkins neu starten diff --git a/core/src/main/resources/hudson/model/UpdateCenter/index.jelly b/core/src/main/resources/hudson/model/UpdateCenter/index.jelly index dfd7d7a6b6..17629e5174 100644 --- a/core/src/main/resources/hudson/model/UpdateCenter/index.jelly +++ b/core/src/main/resources/hudson/model/UpdateCenter/index.jelly @@ -33,11 +33,11 @@ THE SOFTWARE.

${%Installing Plugins/Upgrades}

-
+

${%warning} - +

diff --git a/core/src/main/resources/hudson/model/UpdateCenter/index_de.properties b/core/src/main/resources/hudson/model/UpdateCenter/index_de.properties index 462ec8c259..c379692ad1 100644 --- a/core/src/main/resources/hudson/model/UpdateCenter/index_de.properties +++ b/core/src/main/resources/hudson/model/UpdateCenter/index_de.properties @@ -1,17 +1,17 @@ # The MIT License -# +# # Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi, Harald Wellmann -# +# # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: -# +# # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. -# +# # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -23,4 +23,4 @@ Update\ Center=Aktualisierungen warning=Neu installierte Plugins werden erst nach einem Neustart von Jenkins aktiv. Installing\ Plugins/Upgrades=Installiere Plugins/Aktualisierungen -Restart\ When\ No\ Jobs\ Are\ Running=Neu starten, sobald keine Jobs mehr laufen +Schedule\ Restart=Nach Installation neu starten