Search in sources :

Example 1 with JavaVMArguments

use of com.sun.akuma.JavaVMArguments 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();
}
Also used : StreamTaskListener(hudson.util.StreamTaskListener) ZFSException(org.jvnet.solaris.libzfs.ZFSException) Hudson(hudson.model.Hudson) JavaVMArguments(com.sun.akuma.JavaVMArguments) ByteArrayOutputStream(org.apache.commons.io.output.ByteArrayOutputStream) IOException(java.io.IOException) HudsonIsRestarting(hudson.util.HudsonIsRestarting) ServletException(javax.servlet.ServletException) ZFSException(org.jvnet.solaris.libzfs.ZFSException) IOException(java.io.IOException)

Aggregations

JavaVMArguments (com.sun.akuma.JavaVMArguments)1 Hudson (hudson.model.Hudson)1 HudsonIsRestarting (hudson.util.HudsonIsRestarting)1 StreamTaskListener (hudson.util.StreamTaskListener)1 IOException (java.io.IOException)1 ServletException (javax.servlet.ServletException)1 ByteArrayOutputStream (org.apache.commons.io.output.ByteArrayOutputStream)1 ZFSException (org.jvnet.solaris.libzfs.ZFSException)1