Skip to content
Browse files

[FIXED JENKINS-5047] Restart button now adds a restart action to the

queue instead of restarting immediately.
  • Loading branch information...
1 parent de83a8f commit 40e9dd70f41ee2e5e9def99e4a8e0754abff4f43 @uhafner uhafner committed May 6, 2011
View
52 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 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 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 @@
* 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
*/
@@ -285,6 +287,16 @@ public void doUpgrade(StaplerResponse rsp) throws IOException, ServletException
}
/**
+ * 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
*/
public boolean isDowngradable() {
@@ -309,6 +321,18 @@ public void doDowngrade(StaplerResponse rsp) throws IOException, ServletExceptio
}
/**
+ * 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
*/
@@ -685,6 +709,24 @@ public void schedule() {
}
/**
+ * 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.
*/
public final class ConnectionCheckJob extends UpdateCenterJob {
View
31 core/src/main/resources/hudson/model/UpdateCenter/RestartJenkinsJob/row.jelly
@@ -0,0 +1,31 @@
+<!--
+The MIT License
+
+Copyright (c) 2004-2010, 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.
+-->
+
+<?jelly escape-by-default='true'?>
+<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
+ <tr id="row${it.id}">
+ <td style="vertical-align: top; padding-right:1em">${%Restarting Jenkins}</td>
+ <td ><img src="${imagesURL}/24x24/refresh.png" alt="" /></td>
+ </tr>
+</j:jelly>
View
23 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
View
4 core/src/main/resources/hudson/model/UpdateCenter/index.jelly
@@ -33,11 +33,11 @@ THE SOFTWARE.
<l:main-panel>
<h1>${%Installing Plugins/Upgrades}</h1>
- <form method="post" action="${rootURL}/safeRestart">
+ <form method="post" action="safeRestart">
<p class="warning">
${%warning}
<j:if test="${app.lifecycle.canRestart()}">
- <f:submit value="${%Restart When No Jobs Are Running}" />
+ <f:submit value="${%Schedule Restart}" />
</j:if>
</p>
</form>
View
10 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

0 comments on commit 40e9dd7

Please sign in to comment.
Something went wrong with that request. Please try again.