From eed4a9bb810ceb5a366009c8379b06ed80b833f3 Mon Sep 17 00:00:00 2001 From: Mark Payne Date: Tue, 9 Dec 2014 13:51:15 -0500 Subject: [PATCH] NIFI-145: Added batch scripts and a simple bootstrap.conf file and fixed ShutdownHook to be Java 7 compliant --- .../src/main/resources/bin/nifi-status.bat | 15 +++++++++ .../src/main/resources/bin/start-nifi.bat | 15 +++++++++ .../src/main/resources/bin/stop-nifi.bat | 15 +++++++++ .../src/main/resources/conf/bootstrap.conf | 9 +++++ .../apache/nifi/bootstrap/ShutdownHook.java | 33 ++++++++++++++----- 5 files changed, 79 insertions(+), 8 deletions(-) create mode 100644 nar-bundles/framework-bundle/framework/resources/src/main/resources/bin/nifi-status.bat create mode 100644 nar-bundles/framework-bundle/framework/resources/src/main/resources/bin/start-nifi.bat create mode 100644 nar-bundles/framework-bundle/framework/resources/src/main/resources/bin/stop-nifi.bat create mode 100644 nar-bundles/framework-bundle/framework/resources/src/main/resources/conf/bootstrap.conf diff --git a/nar-bundles/framework-bundle/framework/resources/src/main/resources/bin/nifi-status.bat b/nar-bundles/framework-bundle/framework/resources/src/main/resources/bin/nifi-status.bat new file mode 100644 index 0000000000..9b88349c80 --- /dev/null +++ b/nar-bundles/framework-bundle/framework/resources/src/main/resources/bin/nifi-status.bat @@ -0,0 +1,15 @@ +@echo off + +rem Use JAVA_HOME if it's set; otherwise, just use java +IF "%JAVA_HOME%"=="" (SET JAVA_EXE=java) ELSE (SET JAVA_EXE=%JAVA_HOME%\bin\java.exe) + +SET LIB_DIR=%~dp0..\lib +SET CONF_DIR=%~dp0..\conf + +SET BOOTSTRAP_CONF_FILE=%CONF_DIR%\bootstrap.conf +SET JAVA_ARGS=-Dorg.apache.nifi.boostrap.config.file=%BOOTSTRAP_CONF_FILE% + +SET JAVA_PARAMS=-cp %LIB_DIR%\nifi-bootstrap*.jar -Xms12m -Xmx24m %JAVA_ARGS% org.apache.nifi.bootstrap.RunNiFi +SET BOOTSTRAP_ACTION=status + +cmd.exe /C "%JAVA_EXE%" %JAVA_PARAMS% %BOOTSTRAP_ACTION% diff --git a/nar-bundles/framework-bundle/framework/resources/src/main/resources/bin/start-nifi.bat b/nar-bundles/framework-bundle/framework/resources/src/main/resources/bin/start-nifi.bat new file mode 100644 index 0000000000..c088672900 --- /dev/null +++ b/nar-bundles/framework-bundle/framework/resources/src/main/resources/bin/start-nifi.bat @@ -0,0 +1,15 @@ +@echo off + +rem Use JAVA_HOME if it's set; otherwise, just use java +IF "%JAVA_HOME%"=="" (SET JAVA_EXE=java) ELSE (SET JAVA_EXE=%JAVA_HOME%\bin\java.exe) + +SET LIB_DIR=%~dp0..\lib +SET CONF_DIR=%~dp0..\conf + +SET BOOTSTRAP_CONF_FILE=%CONF_DIR%\bootstrap.conf +SET JAVA_ARGS=-Dorg.apache.nifi.boostrap.config.file=%BOOTSTRAP_CONF_FILE% + +SET JAVA_PARAMS=-cp %LIB_DIR%\nifi-bootstrap*.jar -Xms12m -Xmx24m %JAVA_ARGS% org.apache.nifi.bootstrap.RunNiFi +SET BOOTSTRAP_ACTION=start + +cmd.exe /C "%JAVA_EXE%" %JAVA_PARAMS% %BOOTSTRAP_ACTION% diff --git a/nar-bundles/framework-bundle/framework/resources/src/main/resources/bin/stop-nifi.bat b/nar-bundles/framework-bundle/framework/resources/src/main/resources/bin/stop-nifi.bat new file mode 100644 index 0000000000..753b09fc9d --- /dev/null +++ b/nar-bundles/framework-bundle/framework/resources/src/main/resources/bin/stop-nifi.bat @@ -0,0 +1,15 @@ +@echo off + +rem Use JAVA_HOME if it's set; otherwise, just use java +IF "%JAVA_HOME%"=="" (SET JAVA_EXE=java) ELSE (SET JAVA_EXE=%JAVA_HOME%\bin\java.exe) + +SET LIB_DIR=%~dp0..\lib +SET CONF_DIR=%~dp0..\conf + +SET BOOTSTRAP_CONF_FILE=%CONF_DIR%\bootstrap.conf +SET JAVA_ARGS=-Dorg.apache.nifi.boostrap.config.file=%BOOTSTRAP_CONF_FILE% + +SET JAVA_PARAMS=-cp %LIB_DIR%\nifi-bootstrap*.jar -Xms12m -Xmx24m %JAVA_ARGS% org.apache.nifi.bootstrap.RunNiFi +SET BOOTSTRAP_ACTION=stop + +cmd.exe /C "%JAVA_EXE%" %JAVA_PARAMS% %BOOTSTRAP_ACTION% diff --git a/nar-bundles/framework-bundle/framework/resources/src/main/resources/conf/bootstrap.conf b/nar-bundles/framework-bundle/framework/resources/src/main/resources/conf/bootstrap.conf new file mode 100644 index 0000000000..97d48f85b7 --- /dev/null +++ b/nar-bundles/framework-bundle/framework/resources/src/main/resources/conf/bootstrap.conf @@ -0,0 +1,9 @@ +lib.dir=./lib +conf.dir=./conf +java.arg.1=-Dorg.apache.jasper.compiler.disablejsr199=true + +java.arg.2=-Xms256m +java.arg.3=-Xmx512m + +# Enable Remote Debugging +#java.arg.2=-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8000 \ No newline at end of file diff --git a/nifi-bootstrap/src/main/java/org/apache/nifi/bootstrap/ShutdownHook.java b/nifi-bootstrap/src/main/java/org/apache/nifi/bootstrap/ShutdownHook.java index 142d984548..f804c7c371 100644 --- a/nifi-bootstrap/src/main/java/org/apache/nifi/bootstrap/ShutdownHook.java +++ b/nifi-bootstrap/src/main/java/org/apache/nifi/bootstrap/ShutdownHook.java @@ -53,19 +53,36 @@ public class ShutdownHook extends Thread { } } - try { - nifiProcess.waitFor(WAIT_SECONDS, TimeUnit.SECONDS); - } catch (final InterruptedException ie) { + System.out.println("Waiting for Apache NiFi to finish shutting down..."); + final long startWait = System.nanoTime(); + while ( isAlive(nifiProcess) ) { + final long waitNanos = System.nanoTime() - startWait; + final long waitSeconds = TimeUnit.NANOSECONDS.toSeconds(waitNanos); + if ( waitSeconds >= WAIT_SECONDS ) { + if ( isAlive(nifiProcess) ) { + System.out.println("NiFi has not finished shutting down after " + WAIT_SECONDS + " seconds. Killing process."); + nifiProcess.destroy(); + } + break; + } else { + try { + Thread.sleep(1000L); + } catch (final InterruptedException ie) {} + } } - - if ( nifiProcess.isAlive() ) { - System.out.println("NiFi has not finished shutting down after " + WAIT_SECONDS + " seconds. Killing process."); - } - nifiProcess.destroy(); final File statusFile = runner.getStatusFile(); if ( !statusFile.delete() ) { System.err.println("Failed to delete status file " + statusFile.getAbsolutePath()); } } + + private boolean isAlive(final Process process) { + try { + process.exitValue(); + return false; + } catch (final IllegalThreadStateException itse) { + return true; + } + } }