提交 91815581 编写于 作者: K kohsuke

Adding auto-restart capability when Hudson runs as a Windows service

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@12887 71c3de6d-444a-0410-be80-ed276b4c234a
上级 6eb992e6
......@@ -488,7 +488,7 @@
<dependency>
<groupId>com.sun.winsw</groupId>
<artifactId>winsw</artifactId>
<version>1.1</version>
<version>1.2</version>
<classifier>bin</classifier>
<type>exe</type>
<scope>provided</scope><!-- this isn't really a dependency that Maven should care about, so putting 'provided' -->
......
......@@ -4,6 +4,7 @@ import hudson.ExtensionPoint;
import hudson.model.Hudson;
import java.io.File;
import java.io.IOException;
/**
* Provides the capability for starting/stopping/restarting/uninstalling Hudson.
......@@ -74,8 +75,16 @@ public abstract class Lifecycle implements ExtensionPoint {
* If this life cycle supports a restart of Hudson, do so.
* Otherwise, throw {@link UnsupportedOperationException},
* which is what the default implementation does.
*
* <p>
* The restart operation may happen synchronously (in which case
* this method will never return), or asynchronously (in which
* case this method will successfully return.)
*
* <p>
* Throw an exception if the operation fails unexpectedly.
*/
public void restart() {
public void restart() throws IOException, InterruptedException {
throw new UnsupportedOperationException();
}
}
package hudson.lifecycle;
import org.apache.commons.io.output.ByteArrayOutputStream;
import hudson.util.StreamTaskListener;
import hudson.Launcher.LocalLauncher;
import hudson.FilePath;
import java.io.File;
import java.io.IOException;
/**
* {@link Lifecycle} for Hudson installed as Windows service.
*
* @author Kohsuke Kawaguchi
*/
public class WindowsServiceLifecycle extends Lifecycle {
public void restart() throws IOException, InterruptedException {
File me = getHudsonWar();
File home = me.getParentFile();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
StreamTaskListener task = new StreamTaskListener(baos);
task.getLogger().println("Restarting a service");
int r = new LocalLauncher(task).launch(new String[]{new File(home, "hudson.exe").getPath(), "restart"}, new String[0], task.getLogger(), new FilePath(home)).join();
if(r!=0)
throw new IOException(baos.toString());
}
}
......@@ -2116,6 +2116,10 @@ public final class Hudson extends View implements ItemGroup<TopLevelItem>, Node,
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);
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册