use of hudson.util.StreamTaskListener in project hudson-2.x by hudson.
the class ZFSInstaller method doStart.
/**
* Called from the confirmation screen to actually initiate the migration.
*/
public void doStart(StaplerRequest req, StaplerResponse rsp, @QueryParameter String username, @QueryParameter String password) throws ServletException, IOException {
requirePOST();
Hudson hudson = Hudson.getInstance();
hudson.checkPermission(Hudson.ADMINISTER);
final String datasetName;
ByteArrayOutputStream log = new ByteArrayOutputStream();
StreamTaskListener listener = new StreamTaskListener(log);
try {
datasetName = createZfsFileSystem(listener, username, password);
} catch (Exception e) {
e.printStackTrace(listener.error(e.getMessage()));
if (e instanceof ZFSException) {
ZFSException ze = (ZFSException) e;
if (ze.getCode() == ErrorCode.EZFS_PERM) {
// permission problem. ask the user to give us the root password
req.setAttribute("message", log.toString());
rsp.forward(this, "askRootPassword", req);
return;
}
}
// for other kinds of problems, report and bail out
req.setAttribute("pre", true);
sendError(log.toString(), req, rsp);
return;
}
// file system creation successful, so restart
WebAppController.get().install(new HudsonIsRestarting());
// redirect the user to the manage page
rsp.sendRedirect2(req.getContextPath() + "/manage");
// asynchronously restart, so that we can give a bit of time to the browser to load "restarting..." screen.
new Thread("restart thread") {
@Override
public void run() {
try {
Thread.sleep(5000);
// close all descriptors on exec except stdin,out,err
int sz = LIBC.getdtablesize();
for (int i = 3; i < sz; i++) {
int flags = LIBC.fcntl(i, F_GETFD);
if (flags < 0)
continue;
LIBC.fcntl(i, F_SETFD, flags | FD_CLOEXEC);
}
// re-exec with the system property to indicate where to migrate the data to.
// the 2nd phase is implemented in the migrate method.
JavaVMArguments args = JavaVMArguments.current();
args.setSystemProperty(ZFSInstaller.class.getName() + ".migrate", datasetName);
Daemon.selfExec(args);
} catch (InterruptedException e) {
LOGGER.log(Level.SEVERE, "Restart failed", e);
} catch (IOException e) {
LOGGER.log(Level.SEVERE, "Restart failed", e);
}
}
}.start();
}
Aggregations