Search in sources :

Example 6 with Lifecycle

use of org.graylog2.plugin.lifecycles.Lifecycle in project graylog2-server by Graylog2.

the class GracefulShutdown method doRun.

private void doRun(boolean exit) {
    LOG.info("Graceful shutdown initiated.");
    // Trigger a lifecycle change. Some services are listening for those and will halt operation accordingly.
    serverStatus.shutdown();
    // Give possible load balancers time to recognize state change. State is DEAD because of HALTING.
    LOG.info("Node status: [{}]. Waiting <{}sec> for possible load balancers to recognize state change.", serverStatus.getLifecycle(), configuration.getLoadBalancerRecognitionPeriodSeconds());
    Uninterruptibles.sleepUninterruptibly(configuration.getLoadBalancerRecognitionPeriodSeconds(), TimeUnit.SECONDS);
    activityWriter.write(new Activity("Graceful shutdown initiated.", GracefulShutdown.class));
    /*
         * Wait a second to give for example the calling REST call some time to respond
         * to the client. Using a latch or something here might be a bit over-engineered.
         */
    Uninterruptibles.sleepUninterruptibly(SLEEP_SECS, TimeUnit.SECONDS);
    // Stop REST API service to avoid changes from outside.
    jerseyService.stopAsync();
    // stop all inputs so no new messages can come in
    inputSetupService.stopAsync();
    jerseyService.awaitTerminated();
    inputSetupService.awaitTerminated();
    // Try to flush all remaining messages from the system
    bufferSynchronizerService.stopAsync().awaitTerminated();
    // Stop all services that registered with the shutdown service (e.g. plugins)
    // This must run after the BufferSynchronizerService shutdown to make sure the buffers are empty.
    gracefulShutdownService.stopAsync();
    // stop all maintenance tasks
    periodicalsService.stopAsync().awaitTerminated();
    // Wait until the shutdown service is done
    gracefulShutdownService.awaitTerminated();
    auditEventSender.success(AuditActor.system(serverStatus.getNodeId()), NODE_SHUTDOWN_COMPLETE);
    // Shut down hard with no shutdown hooks running.
    LOG.info("Goodbye.");
    if (exit) {
        System.exit(0);
    }
}
Also used : Activity(org.graylog2.shared.system.activities.Activity)

Aggregations

RawMessage (org.graylog2.plugin.journal.RawMessage)3 IOException (java.io.IOException)2 URL (java.net.URL)2 Properties (java.util.Properties)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 InstrumentedExecutorService (com.codahale.metrics.InstrumentedExecutorService)1 Timed (com.codahale.metrics.annotation.Timed)1 RequestSpecification (io.restassured.specification.RequestSpecification)1 ApiOperation (io.swagger.annotations.ApiOperation)1 InetSocketAddress (java.net.InetSocketAddress)1 MalformedURLException (java.net.MalformedURLException)1 List (java.util.List)1 ExecutorService (java.util.concurrent.ExecutorService)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 PUT (javax.ws.rs.PUT)1 Path (javax.ws.rs.Path)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 ConsumerConfig (kafka.consumer.ConsumerConfig)1 ConsumerIterator (kafka.consumer.ConsumerIterator)1 ConsumerTimeoutException (kafka.consumer.ConsumerTimeoutException)1