You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by ma...@apache.org on 2022/02/28 19:29:52 UTC

[nifi] branch main updated: NIFI-9688 Improve Logback shutdown handling (#5805)

This is an automated email from the ASF dual-hosted git repository.

markap14 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi.git


The following commit(s) were added to refs/heads/main by this push:
     new 52f2139  NIFI-9688 Improve Logback shutdown handling (#5805)
52f2139 is described below

commit 52f21390dbbf619bb38699d66df3cf6ed322e303
Author: exceptionfactory <ex...@apache.org>
AuthorDate: Mon Feb 28 14:29:44 2022 -0500

    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-framework/nifi-resources/src/main/resources/bin/nifi-env.sh  | 3 +++
 .../nifi-framework/nifi-resources/src/main/resources/conf/logback.xml | 2 ++
 .../nifi/web/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 4922351..de152ee 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 5e3faa2..fe60fbf 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 @@
 -->
 
 <configuration scan="true" scanPeriod="30 seconds">
+    <shutdownHook class="ch.qos.logback.core.hook.DelayingShutdownHook" />
+
     <contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator">
         <resetJUL>true</resetJUL>
     </contextListener>
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 f91c7f2..4cac25e 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 343e2e8..a149cb7 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 c9bc033..65665ce 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 @@
 -->
 
 <configuration scan="true" scanPeriod="30 seconds">
+    <shutdownHook class="ch.qos.logback.core.hook.DelayingShutdownHook" />
+
     <contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator">
         <resetJUL>true</resetJUL>
     </contextListener>
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 b4e3b82..80bd3ed 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 c9bc033..65665ce 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 @@
 -->
 
 <configuration scan="true" scanPeriod="30 seconds">
+    <shutdownHook class="ch.qos.logback.core.hook.DelayingShutdownHook" />
+
     <contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator">
         <resetJUL>true</resetJUL>
     </contextListener>
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 da7940a..0ed0ab0 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 c9bc033..65665ce 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 @@
 -->
 
 <configuration scan="true" scanPeriod="30 seconds">
+    <shutdownHook class="ch.qos.logback.core.hook.DelayingShutdownHook" />
+
     <contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator">
         <resetJUL>true</resetJUL>
     </contextListener>