How to configure a graceful shutdown of JBoss EAP for OpenShift ?
Environment
- OpenShift Container Platform
- 3.11
- 4
- JBoss EAP for OpenShift
- 7.1 or later
- 8.0
Issue
- What is the default
shutdownmode of JBoss EAP for OpenShift? - How do I adjust the shutdown
timeoutconfiguration 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 shutdownby JBoss CLI with60seconds timeout. JBoss EAP will wait up to60seconds to complete in-flight requests at the start of shutdown. -
We can also configure graceful shutdown timeout other than
60seconds by the following steps.- Set the
CLI_GRACEFUL_SHUTDOWNenvironment variable tofalseinDeploymentConfigorDeployment. IfCLI_GRACEFUL_SHUTDOWNis set to a non-empty string value, the default graceful shutdown process byjboss-cli.sh -c "shutdown --timeout=60"is disabled. It meansTERMsignal from the container runtime will no longer initiate shutdown.
$ oc set env dc/<deployment-config-name> CLI_GRACEFUL_SHUTDOWN=false - Set the
-
Configure the
preStoplifecycle hook in Deployment or DeploymentConfig.- In this example, the graceful shutdown timeout is extended to
120seconds. If the new timeout value is longer than (terminationGracePeriodSeconds- 15 seconds), it is also required to extendterminationGracePeriodSecondstimeout more than the graceful shutdown timeout.
- In this example, the graceful shutdown timeout is extended to
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
Related solutions
- For a complete explanation of the scripts and how to troubleshoot, see the solution What does probe checks of JBoss EAP 7 on OpenShift ?.
- For SigTERM discussion on EAP see JBossAS process (...) received TERM signal in OpenShift.
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.