From 293f75583e0732e3ad54662546e889f4a6971f8a Mon Sep 17 00:00:00 2001 From: Brian Stansberry Date: Tue, 16 Jun 2015 19:12:37 -0500 Subject: [PATCH] [WFCORE-765] ServerDomainProcessShutdownHandler shouldn't fail if shutdown is already underway --- .../ServerDomainProcessShutdownHandler.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/server/src/main/java/org/jboss/as/server/operations/ServerDomainProcessShutdownHandler.java b/server/src/main/java/org/jboss/as/server/operations/ServerDomainProcessShutdownHandler.java index f3339f3b7ea..39c57176056 100644 --- a/server/src/main/java/org/jboss/as/server/operations/ServerDomainProcessShutdownHandler.java +++ b/server/src/main/java/org/jboss/as/server/operations/ServerDomainProcessShutdownHandler.java @@ -24,6 +24,7 @@ import java.util.EnumSet; + import org.jboss.as.controller.OperationContext; import org.jboss.as.controller.OperationFailedException; import org.jboss.as.controller.OperationStepHandler; @@ -99,12 +100,17 @@ public void handleResult(OperationContext.ResultAction resultAction, OperationCo //to stop new requests being accepted as it is shutting down final ServiceRegistry registry = context.getServiceRegistry(false); - final ServiceController gracefulController = (ServiceController) registry.getRequiredService(GracefulShutdownService.SERVICE_NAME); - gracefulController.getValue().startGracefulShutdown(); - - final ServiceController suspendControllerServiceController = (ServiceController) registry.getRequiredService(SuspendController.SERVICE_NAME); - final SuspendController suspendController = suspendControllerServiceController.getValue(); - suspendController.suspend(timeout > 0 ? timeout * 1000 : timeout); + // WFCORE-765 if either of the services we use are not present, graceful shutdown + // is not possible, but don't fail. The services may be missing if the server + // is already shutting down due to receiving a SIGINT + final ServiceController gracefulController = (ServiceController) registry.getService(GracefulShutdownService.SERVICE_NAME); + if (gracefulController != null) { + final ServiceController suspendControllerServiceController = (ServiceController) registry.getService(SuspendController.SERVICE_NAME); + if (suspendControllerServiceController != null) { + gracefulController.getValue().startGracefulShutdown(); + suspendControllerServiceController.getValue().suspend(timeout > 0 ? timeout * 1000 : timeout); + } + } } } });