Search in sources :

Example 1 with Lifecycle

use of hudson.lifecycle.Lifecycle 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();
}
Also used : Lifecycle(hudson.lifecycle.Lifecycle) IOException(java.io.IOException) HudsonIsRestarting(hudson.util.HudsonIsRestarting) UDPBroadcastThread(hudson.UDPBroadcastThread)

Example 2 with Lifecycle

use of hudson.lifecycle.Lifecycle 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();
}
Also used : Lifecycle(hudson.lifecycle.Lifecycle) IOException(java.io.IOException) HudsonIsRestarting(hudson.util.HudsonIsRestarting) UDPBroadcastThread(hudson.UDPBroadcastThread)

Aggregations

UDPBroadcastThread (hudson.UDPBroadcastThread)2 Lifecycle (hudson.lifecycle.Lifecycle)2 HudsonIsRestarting (hudson.util.HudsonIsRestarting)2 IOException (java.io.IOException)2