提交 9fe98369 编写于 作者: K kohsuke

improved the restart by using AJAX. See http://d.hatena.ne.jp/ssogabe/20090506/1241552799

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@17794 71c3de6d-444a-0410-be80-ed276b4c234a
上级 ea0983c6
......@@ -2750,21 +2750,36 @@ public final class Hudson extends Node implements ItemGroup<TopLevelItem>, Stapl
/**
* Perform a restart of Hudson, if we can.
*
* This first replaces "app" to {@link HudsonIsRestarting}
*/
public void doRestart(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException {
requirePOST();
checkPermission(ADMINISTER);
try {
Lifecycle.get().restart();
servletContext.setAttribute("app",new HudsonIsRestarting());
rsp.sendRedirect2(".");
} catch (UnsupportedOperationException e) {
sendError("Restart is not supported in this running mode.",req,rsp);
} catch (IOException e) {
sendError(e,req,rsp);
} catch (InterruptedException e) {
sendError(e,req,rsp);
if(Stapler.getCurrentRequest().getMethod().equals("GET")) {
req.getView(this,"_restart.jelly").forward(req,rsp);
return;
}
final Lifecycle lifecycle = Lifecycle.get();
if(!lifecycle.canRestart())
sendError("Restart is not supported in this running mode.",req,rsp);
servletContext.setAttribute("app",new HudsonIsRestarting());
rsp.sendRedirect2(".");
new Thread("restart thread") {
@Override
public void run() {
try {
// give some time for the browser to load the "reloading" page
Thread.sleep(5000);
lifecycle.restart();
} catch (InterruptedException e) {
LOGGER.log(Level.WARNING, "Failed to restart Hudson",e);
} catch (IOException e) {
LOGGER.log(Level.WARNING, "Failed to restart Hudson",e);
}
}
}.start();
}
/**
......
<!--
The MIT License
Copyright (c) 2004-2009, Sun Microsystems, Inc.
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.
-->
<!-- Delete view -->
<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" xmlns:i="jelly:fmt">
<l:layout title="Restart Hudson">
<st:include page="sidepanel.jelly" />
<l:main-panel>
<form method="post" action="restart">
${%Are you sure about restarting Hudson?}
<f:submit value="${%Yes}" />
</form>
</l:main-panel>
</l:layout>
</j:jelly>
\ No newline at end of file
......@@ -1482,7 +1482,12 @@ function applySafeRedirector(url) {
}
},
onSuccess: function(rsp) {
window.location.replace(url);
if(rsp.status!=200) {
// if connection fails, somehow Prototype thinks it's a success
window.setTimeout(statusChecker,5000);
} else {
window.location.replace(url);
}
}
});
}, 5000);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册