use of hudson.util.HudsonIsRestarting in project hudson-2.x by hudson.
the class Hudson method safeRestart.
/**
* Queues up a restart to be performed once there are no builds currently running.
* @since 1.332
*/
public void safeRestart() throws RestartNotSupportedException {
final Lifecycle lifecycle = Lifecycle.get();
// verify that Hudson is restartable
lifecycle.verifyRestartable();
// Quiet down so that we won't launch new builds.
isQuietingDown = true;
new Thread("safe-restart thread") {
final String exitUser = getAuthentication().getName();
@Override
public void run() {
try {
SecurityContextHolder.getContext().setAuthentication(ACL.SYSTEM);
// Wait 'til we have no active executors.
doQuietDown(true, 0);
// Make sure isQuietingDown is still true.
if (isQuietingDown) {
WebAppController.get().install(new HudsonIsRestarting());
// give some time for the browser to load the "reloading" page
LOGGER.info("Restart in 10 seconds");
Thread.sleep(10000);
LOGGER.severe(String.format("Restarting VM as requested by %s", exitUser));
for (RestartListener listener : RestartListener.all()) {
listener.onRestart();
}
lifecycle.restart();
} else {
LOGGER.info("Safe-restart mode cancelled");
}
} catch (InterruptedException e) {
LOGGER.log(Level.WARNING, "Failed to restart Hudson", e);
} catch (IOException e) {
LOGGER.log(Level.WARNING, "Failed to restart Hudson", e);
}
}
}.start();
}
use of hudson.util.HudsonIsRestarting 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();
}
use of hudson.util.HudsonIsRestarting in project hudson-2.x by hudson.
the class Hudson method restart.
/**
* Performs a restart.
*/
public void restart() throws RestartNotSupportedException {
final Lifecycle lifecycle = Lifecycle.get();
// verify that Hudson is restartable
lifecycle.verifyRestartable();
WebAppController.get().install(new HudsonIsRestarting());
new Thread("restart thread") {
final String exitUser = getAuthentication().getName();
@Override
public void run() {
try {
SecurityContextHolder.getContext().setAuthentication(ACL.SYSTEM);
// give some time for the browser to load the "reloading" page
Thread.sleep(5000);
LOGGER.severe(String.format("Restarting VM as requested by %s", exitUser));
for (RestartListener listener : RestartListener.all()) {
listener.onRestart();
}
lifecycle.restart();
} catch (InterruptedException e) {
LOGGER.log(Level.WARNING, "Failed to restart Hudson", e);
} catch (IOException e) {
LOGGER.log(Level.WARNING, "Failed to restart Hudson", e);
}
}
}.start();
}
Aggregations