提交 e20e94d5 编写于 作者: K kohsuke

Added SMF life cycle.

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@14483 71c3de6d-444a-0410-be80-ed276b4c234a
上级 b656cd85
......@@ -6,6 +6,9 @@ import hudson.model.Hudson;
import java.io.File;
import java.io.IOException;
import org.apache.commons.io.IOUtils;
import org.apache.commons.io.FileUtils;
/**
* Provides the capability for starting/stopping/restarting/uninstalling Hudson.
*
......@@ -72,9 +75,19 @@ public abstract class Lifecycle implements ExtensionPoint {
/**
* Replaces hudson.war by the given file.
*
* <p>
* On some system, most notably Windows, a file being in use cannot be changed,
* so rewriting <tt>hudson.war</tt> requires some special trick. Override this method
* to do so.
*/
public void rewriteHudsonWar(File by) throws IOException {
throw new UnsupportedOperationException();
File dest = getHudsonWar();
// this should be impossible given the canRewriteHudsonWar method,
// but let's be defensive
if(dest==null) throw new IOException("hudson.war location is not known.");
FileUtils.copyFile(by, dest);
}
/**
......@@ -82,8 +95,7 @@ public abstract class Lifecycle implements ExtensionPoint {
*/
public boolean canRewriteHudsonWar() {
// if we don't know where hudson.war is, it's impossible to replace.
if(getHudsonWar()==null) return false;
return isOverridden("rewriteHudsonWar",File.class);
return getHudsonWar()!=null;
}
private boolean isOverridden(String methodName, Class... types) {
......
package hudson.lifecycle;
import java.io.IOException;
/**
* {@link Lifecycle} for Hudson installed as SMF service.
*
* @author Kohsuke Kawaguchi
*/
public class SolarisSMFLifecycle extends Lifecycle {
/**
* In SMF managed environment, just commit a suicide and the service will be restarted by SMF.
*/
@Override
public void restart() throws IOException, InterruptedException {
System.exit(0);
}
}
......@@ -57,6 +57,10 @@ public class WindowsServiceLifecycle extends Lifecycle {
}
}
/**
* On Windows, hudson.war is locked, so we place a new version under a special name,
* which is picked up by the service wrapper upon restart.
*/
@Override
public void rewriteHudsonWar(File by) throws IOException {
File rootDir = Hudson.getInstance().getRootDir();
......@@ -67,6 +71,7 @@ public class WindowsServiceLifecycle extends Lifecycle {
w.close();
}
@Override
public void restart() throws IOException, InterruptedException {
File me = getHudsonWar();
File home = me.getParentFile();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册