NIFI-894 Introducing a lock file to communicate from boostrap to NiFi that a shutdown is in progress.

This commit is contained in:
Bryan Bende 2015-08-25 15:43:52 -04:00
parent f34d73e73e
commit d39848f06e
1 changed files with 31 additions and 0 deletions

View File

@ -235,6 +235,16 @@ public class RunNiFi {
return statusFile; 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 { private Properties loadProperties(final Logger logger) throws IOException {
final Properties props = new Properties(); final Properties props = new Properties();
final File statusFile = getStatusFile(logger); final File statusFile = getStatusFile(logger);
@ -498,6 +508,12 @@ public class RunNiFi {
return; 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 Properties nifiProps = loadProperties(logger);
final String secretKey = nifiProps.getProperty("secret.key"); final String secretKey = nifiProps.getProperty("secret.key");
@ -576,6 +592,10 @@ public class RunNiFi {
} }
} catch (final IOException ioe) { } catch (final IOException ioe) {
logger.error("Failed to send shutdown command to port {} due to {}", new Object[]{port, ioe.toString(), 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; 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(); final ProcessBuilder builder = new ProcessBuilder();
if (!bootstrapConfigFile.exists()) { if (!bootstrapConfigFile.exists()) {
@ -805,6 +830,12 @@ public class RunNiFi {
return; return;
} }
final File lockFile = getLockFile(defaultLogger);
if (lockFile.exists()) {
defaultLogger.info("A shutdown was initiated. Will not restart NiFi");
return;
}
final boolean previouslyStarted = getNifiStarted(); final boolean previouslyStarted = getNifiStarted();
if (!previouslyStarted) { if (!previouslyStarted) {
defaultLogger.info("NiFi never started. Will not restart NiFi"); defaultLogger.info("NiFi never started. Will not restart NiFi");