Skip to content

Commit

Permalink
[FIXED JENKINS-5047] Restart button now adds a restart action to the
Browse files Browse the repository at this point in the history
queue instead of restarting immediately.
  • Loading branch information
uhafner committed May 6, 2011
1 parent de83a8f commit 40e9dd7
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 12 deletions.
52 changes: 47 additions & 5 deletions 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
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -284,6 +286,16 @@ public void doUpgrade(StaplerResponse rsp) throws IOException, ServletException
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
*/
Expand All @@ -308,6 +320,18 @@ public void doDowngrade(StaplerResponse rsp) throws IOException, ServletExceptio
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
Expand Down Expand Up @@ -684,6 +708,24 @@ public Future<UpdateCenterJob> submit() {
}
}

/**
* 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.
*/
Expand Down
@@ -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>
@@ -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
4 changes: 2 additions & 2 deletions core/src/main/resources/hudson/model/UpdateCenter/index.jelly
Expand Up @@ -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>
Expand Down
@@ -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
Expand All @@ -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.