Runtime.getRuntime().addShutdownHook(new Thread("service starter") {
public void run() {
try {
if(!oldRoot.equals(installationDir)) {
LOGGER.info("Moving data");
Move mv = new Move();
Project p = new Project();
p.addBuildListener(createLogger());
mv.setProject(p);
FileSet fs = new FileSet();
fs.setDir(oldRoot);
fs.setExcludes("war/**"); // we can't really move the exploded war.
mv.addFileset(fs);
mv.setTodir(installationDir);
mv.setFailOnError(false); // plugins can also fail to move
mv.execute();
}
LOGGER.info("Starting a Windows service");
StreamTaskListener task = StreamTaskListener.fromStdout();
int r = WindowsSlaveInstaller.runElevated(
new File(installationDir, "jenkins.exe"), "start", task, installationDir);