You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by bb...@apache.org on 2015/08/27 18:51:27 UTC
nifi git commit: NIFI-894 Introducing a lock file to communicate from
boostrap to NiFi that a shutdown is in progress.
Repository: nifi
Updated Branches:
refs/heads/master f34d73e73 -> d39848f06
NIFI-894 Introducing a lock file to communicate from boostrap to NiFi that a shutdown is in progress.
Project: http://git-wip-us.apache.org/repos/asf/nifi/repo
Commit: http://git-wip-us.apache.org/repos/asf/nifi/commit/d39848f0
Tree: http://git-wip-us.apache.org/repos/asf/nifi/tree/d39848f0
Diff: http://git-wip-us.apache.org/repos/asf/nifi/diff/d39848f0
Branch: refs/heads/master
Commit: d39848f06eff3fa6c53a6632ccb8a9b67c60582f
Parents: f34d73e
Author: Bryan Bende <bb...@apache.org>
Authored: Tue Aug 25 15:43:52 2015 -0400
Committer: Bryan Bende <bb...@apache.org>
Committed: Thu Aug 27 10:06:02 2015 -0400
----------------------------------------------------------------------
.../java/org/apache/nifi/bootstrap/RunNiFi.java | 31 ++++++++++++++++++++
1 file changed, 31 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/nifi/blob/d39848f0/nifi-bootstrap/src/main/java/org/apache/nifi/bootstrap/RunNiFi.java
----------------------------------------------------------------------
diff --git a/nifi-bootstrap/src/main/java/org/apache/nifi/bootstrap/RunNiFi.java b/nifi-bootstrap/src/main/java/org/apache/nifi/bootstrap/RunNiFi.java
index 636fd4a..1299c6d 100644
--- a/nifi-bootstrap/src/main/java/org/apache/nifi/bootstrap/RunNiFi.java
+++ b/nifi-bootstrap/src/main/java/org/apache/nifi/bootstrap/RunNiFi.java
@@ -235,6 +235,16 @@ public class RunNiFi {
return statusFile;
}
+ public File getLockFile(final Logger logger) {
+ final File confDir = bootstrapConfigFile.getParentFile();
+ final File nifiHome = confDir.getParentFile();
+ final File bin = new File(nifiHome, "bin");
+ final File lockFile = new File(bin, "nifi.lock");
+
+ logger.debug("Lock File: {}", lockFile);
+ return lockFile;
+ }
+
private Properties loadProperties(final Logger logger) throws IOException {
final Properties props = new Properties();
final File statusFile = getStatusFile(logger);
@@ -498,6 +508,12 @@ public class RunNiFi {
return;
}
+ // indicate that a stop command is in progress
+ final File lockFile = getLockFile(logger);
+ if (!lockFile.exists()) {
+ lockFile.createNewFile();
+ }
+
final Properties nifiProps = loadProperties(logger);
final String secretKey = nifiProps.getProperty("secret.key");
@@ -576,6 +592,10 @@ public class RunNiFi {
}
} catch (final IOException ioe) {
logger.error("Failed to send shutdown command to port {} due to {}", new Object[]{port, ioe.toString(), ioe});
+ } finally {
+ if (lockFile.exists() && !lockFile.delete()) {
+ logger.error("Failed to delete lock file {}; this file should be cleaned up manually", lockFile);
+ }
}
}
@@ -624,6 +644,11 @@ public class RunNiFi {
return;
}
+ final File prevLockFile = getLockFile(cmdLogger);
+ if (prevLockFile.exists() && !prevLockFile.delete()){
+ cmdLogger.warn("Failed to delete previous lock file {}; this file should be cleaned up manually", prevLockFile);
+ }
+
final ProcessBuilder builder = new ProcessBuilder();
if (!bootstrapConfigFile.exists()) {
@@ -805,6 +830,12 @@ public class RunNiFi {
return;
}
+ final File lockFile = getLockFile(defaultLogger);
+ if (lockFile.exists()) {
+ defaultLogger.info("A shutdown was initiated. Will not restart NiFi");
+ return;
+ }
+
final boolean previouslyStarted = getNifiStarted();
if (!previouslyStarted) {
defaultLogger.info("NiFi never started. Will not restart NiFi");