From 52f21390dbbf619bb38699d66df3cf6ed322e303 Mon Sep 17 00:00:00 2001 From: exceptionfactory Date: Mon, 28 Feb 2022 14:29:44 -0500 Subject: [PATCH] NIFI-9688 Improve Logback shutdown handling (#5805) * NIFI-9688 Improved Logback shutdown handling - Added environment variable to disable Logback shutdown on web application termination - Added shutdown hook to Logback configuration - Added Logback shutdown hook configuration to system tests --- .../nifi-resources/src/main/resources/bin/nifi-env.sh | 3 +++ .../nifi-resources/src/main/resources/conf/logback.xml | 2 ++ .../contextlistener/ApplicationStartupContextListener.java | 4 ++-- .../src/test/resources/conf/clustered/node1/bootstrap.conf | 3 +++ .../src/test/resources/conf/clustered/node1/logback.xml | 2 ++ .../src/test/resources/conf/clustered/node2/bootstrap.conf | 3 +++ .../src/test/resources/conf/clustered/node2/logback.xml | 2 ++ .../src/test/resources/conf/default/bootstrap.conf | 3 +++ .../src/test/resources/conf/default/logback.xml | 2 ++ 9 files changed, 22 insertions(+), 2 deletions(-) diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-resources/src/main/resources/bin/nifi-env.sh b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-resources/src/main/resources/bin/nifi-env.sh index 4922351aa8..de152eea5e 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-resources/src/main/resources/bin/nifi-env.sh +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-resources/src/main/resources/bin/nifi-env.sh @@ -50,6 +50,9 @@ export NIFI_PID_DIR NIFI_LOG_DIR="$(setOrDefault "$NIFI_LOG_DIR" "$NIFI_HOME/logs")" export NIFI_LOG_DIR +# Disable automatic Logback Initializer to avoid shutdown on web application termination +export logbackDisableServletContainerInitializer="true" + # Set to false to force the use of Keytab controller service in processors # that use Kerberos. If true, these processors will allow configuration of keytab # and principal directly within the processor. If false, these processors will be diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-resources/src/main/resources/conf/logback.xml b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-resources/src/main/resources/conf/logback.xml index 5e3faa2698..fe60fbf6e7 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-resources/src/main/resources/conf/logback.xml +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-resources/src/main/resources/conf/logback.xml @@ -15,6 +15,8 @@ --> + + true diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/contextlistener/ApplicationStartupContextListener.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/contextlistener/ApplicationStartupContextListener.java index f91c7f21b7..4cac25ee21 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/contextlistener/ApplicationStartupContextListener.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/contextlistener/ApplicationStartupContextListener.java @@ -95,9 +95,9 @@ public class ApplicationStartupContextListener implements ServletContextListener @Override public void contextDestroyed(ServletContextEvent sce) { - logger.info("Initiating shutdown of flow service..."); + logger.info("Flow Service shutdown started"); shutdown(); - logger.info("Flow service termination completed."); + logger.info("Flow Service shutdown completed"); } private void shutdown() { diff --git a/nifi-system-tests/nifi-system-test-suite/src/test/resources/conf/clustered/node1/bootstrap.conf b/nifi-system-tests/nifi-system-test-suite/src/test/resources/conf/clustered/node1/bootstrap.conf index 343e2e8854..a149cb7e16 100644 --- a/nifi-system-tests/nifi-system-test-suite/src/test/resources/conf/clustered/node1/bootstrap.conf +++ b/nifi-system-tests/nifi-system-test-suite/src/test/resources/conf/clustered/node1/bootstrap.conf @@ -30,3 +30,6 @@ java.arg.14=-Djava.awt.headless=true #java.arg.debug=-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8002 java.arg.nodeNum=-DnodeNumber=1 + +# Disable Logback web shutdown hook using System property +java.arg.logbackShutdown=-DlogbackDisableServletContainerInitializer=true diff --git a/nifi-system-tests/nifi-system-test-suite/src/test/resources/conf/clustered/node1/logback.xml b/nifi-system-tests/nifi-system-test-suite/src/test/resources/conf/clustered/node1/logback.xml index c9bc0330f5..65665cebf9 100644 --- a/nifi-system-tests/nifi-system-test-suite/src/test/resources/conf/clustered/node1/logback.xml +++ b/nifi-system-tests/nifi-system-test-suite/src/test/resources/conf/clustered/node1/logback.xml @@ -15,6 +15,8 @@ --> + + true diff --git a/nifi-system-tests/nifi-system-test-suite/src/test/resources/conf/clustered/node2/bootstrap.conf b/nifi-system-tests/nifi-system-test-suite/src/test/resources/conf/clustered/node2/bootstrap.conf index b4e3b82605..80bd3ed93d 100644 --- a/nifi-system-tests/nifi-system-test-suite/src/test/resources/conf/clustered/node2/bootstrap.conf +++ b/nifi-system-tests/nifi-system-test-suite/src/test/resources/conf/clustered/node2/bootstrap.conf @@ -30,3 +30,6 @@ java.arg.14=-Djava.awt.headless=true #java.arg.debug=-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8003 java.arg.nodeNum=-DnodeNumber=2 + +# Disable Logback web shutdown hook using System property +java.arg.logbackShutdown=-DlogbackDisableServletContainerInitializer=true diff --git a/nifi-system-tests/nifi-system-test-suite/src/test/resources/conf/clustered/node2/logback.xml b/nifi-system-tests/nifi-system-test-suite/src/test/resources/conf/clustered/node2/logback.xml index c9bc0330f5..65665cebf9 100644 --- a/nifi-system-tests/nifi-system-test-suite/src/test/resources/conf/clustered/node2/logback.xml +++ b/nifi-system-tests/nifi-system-test-suite/src/test/resources/conf/clustered/node2/logback.xml @@ -15,6 +15,8 @@ --> + + true diff --git a/nifi-system-tests/nifi-system-test-suite/src/test/resources/conf/default/bootstrap.conf b/nifi-system-tests/nifi-system-test-suite/src/test/resources/conf/default/bootstrap.conf index da7940a918..0ed0ab0fda 100644 --- a/nifi-system-tests/nifi-system-test-suite/src/test/resources/conf/default/bootstrap.conf +++ b/nifi-system-tests/nifi-system-test-suite/src/test/resources/conf/default/bootstrap.conf @@ -28,3 +28,6 @@ java.arg.3=-Xmx512m java.arg.14=-Djava.awt.headless=true #java.arg.debug=-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8002 + +# Disable Logback web shutdown hook using System property +java.arg.logbackShutdown=-DlogbackDisableServletContainerInitializer=true diff --git a/nifi-system-tests/nifi-system-test-suite/src/test/resources/conf/default/logback.xml b/nifi-system-tests/nifi-system-test-suite/src/test/resources/conf/default/logback.xml index c9bc0330f5..65665cebf9 100644 --- a/nifi-system-tests/nifi-system-test-suite/src/test/resources/conf/default/logback.xml +++ b/nifi-system-tests/nifi-system-test-suite/src/test/resources/conf/default/logback.xml @@ -15,6 +15,8 @@ --> + + true