How to configure a graceful shutdown of JBoss EAP for OpenShift ?

Solution Verified - Updated

Environment

  • OpenShift Container Platform
    • 3.11
    • 4
  • JBoss EAP for OpenShift
    • 7.1 or later
    • 8.0

Issue

  • What is the default shutdown mode of JBoss EAP for OpenShift?
  • How do I adjust the shutdown timeout configuration on JBoss EAP for OpenShift?
  • How do I change JBoss EAP for OpenShift graceful shutdown timeout?

Resolution

  • The default shutdown mode of JBoss EAP for OpenShift is graceful shutdown by JBoss CLI with 60 seconds timeout. JBoss EAP will wait up to 60 seconds to complete in-flight requests at the start of shutdown.

  • We can also configure graceful shutdown timeout other than 60 seconds by the following steps.

    • Set the CLI_GRACEFUL_SHUTDOWN environment variable to false in DeploymentConfig or Deployment. If CLI_GRACEFUL_SHUTDOWN is set to a non-empty string value, the default graceful shutdown process by jboss-cli.sh -c "shutdown --timeout=60" is disabled. It means TERM signal from the container runtime will no longer initiate shutdown.
    $ oc set env dc/<deployment-config-name> CLI_GRACEFUL_SHUTDOWN=false
    
  • Configure the preStop lifecycle hook in Deployment or DeploymentConfig.

    • In this example, the graceful shutdown timeout is extended to 120 seconds. If the new timeout value is longer than (terminationGracePeriodSeconds - 15 seconds), it is also required to extend terminationGracePeriodSeconds timeout more than the graceful shutdown timeout.
apiVersion: apps.openshift.io/v1
kind: DeploymentConfig
...
spec:
  template:
    spec:
      containers:
      - env:
        - name: CLI_GRACEFUL_SHUTDOWN
          value: "false"
        image: image-registry.openshift-image-registry.svc:5000/...
        imagePullPolicy: Always
        lifecycle:                             <<<===
          preStop:                             <<<===
            exec:                              <<<===
              command:                         <<<===
              - /opt/eap/bin/jboss-cli.sh      <<<===
              - -c                             <<<===
              - :shutdown(suspend-timeout=120) <<<=== timeout is deprecated from JBoss EAP 7.3. suspended-timeout is recommended instead of timeout.
      ...
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 135   <<<===

NOTE: Until JBoss EAP 7.4, it was located in /opt/eap/, but starting from JBoss EAP 8.0, it is located in /opt/server/. Therefore, in the case of JBoss EAP 8.0, the path to jboss-cli.sh is /opt/server/bin/jboss-cli.sh.

  • If shutdown by TERM signal is disabled by CLI_GRACEFUL_SHUTDOWN=false, the following message shows during container startup.

    INFO Using CLI Graceful Shutdown instead of TERM signal
    
  • We can confirm new graceful shutdown timeout in the following message at the beginning of shutdown:

    00:44:43,135 INFO  [org.jboss.as.server] (management-handler-thread - 1) WFLYSRV0211: Suspending server with 120000 ms timeout.
    

Root Cause

Components
Category

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.