Github user apiri commented on a diff in the pull request: https://github.com/apache/nifi-minifi/pull/10#discussion_r59926319 --- Diff: minifi-bootstrap/src/main/java/org/apache/nifi/minifi/bootstrap/RunMiNiFi.java --- @@ -567,6 +586,104 @@ public void dump(final File dumpFile) throws IOException { } } + public void reload() throws IOException { + final Logger logger = cmdLogger; + final Integer port = getCurrentPort(logger); + if (port == null) { + logger.info("Apache MiNiFi is not currently running"); + return; + } + + // indicate that a reload command is in progress + final File reloadLockFile = getReloadFile(logger); + if (!reloadLockFile.exists()) { + reloadLockFile.createNewFile(); + } + + final Properties nifiProps = loadProperties(logger); + final String secretKey = nifiProps.getProperty("secret.key"); + final String pid = nifiProps.getProperty("pid"); + + try (final Socket socket = new Socket()) { + logger.debug("Connecting to MiNiFi instance"); + socket.setSoTimeout(10000); + socket.connect(new InetSocketAddress("localhost", port)); + logger.debug("Established connection to MiNiFi instance."); + socket.setSoTimeout(10000); + + logger.debug("Sending RELOAD Command to port {}", port); + final OutputStream out = socket.getOutputStream(); + out.write((RELOAD_CMD + " " + secretKey + "\n").getBytes(StandardCharsets.UTF_8)); + out.flush(); + socket.shutdownOutput(); + + final InputStream in = socket.getInputStream(); + int lastChar; + final StringBuilder sb = new StringBuilder(); + while ((lastChar = in.read()) > -1) { + sb.append((char) lastChar); + } + final String response = sb.toString().trim(); + + logger.debug("Received response to RELOAD command: {}", response); + + if (RELOAD_CMD.equals(response)) { + logger.info("Apache MiNiFi has accepted the Reload Command and is reloading"); + + if (pid != null) { + final Properties bootstrapProperties = getBootstrapProperties(); + + String gracefulShutdown = bootstrapProperties.getProperty(GRACEFUL_SHUTDOWN_PROP, DEFAULT_GRACEFUL_SHUTDOWN_VALUE); + int gracefulShutdownSeconds; + try { + gracefulShutdownSeconds = Integer.parseInt(gracefulShutdown); + } catch (final NumberFormatException nfe) { + gracefulShutdownSeconds = Integer.parseInt(DEFAULT_GRACEFUL_SHUTDOWN_VALUE); + } + + final long startWait = System.nanoTime(); + while (isProcessRunning(pid, logger)) { + logger.info("Waiting for Apache MiNiFi to finish shutting down..."); + final long waitNanos = System.nanoTime() - startWait; + final long waitSeconds = TimeUnit.NANOSECONDS.toSeconds(waitNanos); + if (waitSeconds >= gracefulShutdownSeconds && gracefulShutdownSeconds > 0) { + if (isProcessRunning(pid, logger)) { + logger.warn("MiNiFi has not finished shutting down after {} seconds. Killing process.", gracefulShutdownSeconds); --- End diff -- Sufficient to note that the reload is occurring in these statements?
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---