Uploaded image for project: 'Apache NiFi'
  1. Apache NiFi
  2. NIFI-2199

NiFi cannot be restarted through SSH (nifi.sh hangs)

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 1.0.0, 0.5.1, 0.7.0, 0.6.1, 1.2.0
    • 1.3.0
    • Core Framework

    Description

      When NiFi is to restarted using SSH from remote host, nifi.sh causes SSH to hang on open io streams.

      Steps to reproduce:
      1. HostA - NiFi instalation
      2. HostB - client machine
      3. log to HostB
      4. issue a command

      ssh root@HostA /etc/init.d/nifi restart
      

      Expected behavior: NiFi is restarted, SSH command exits with 0
      Actual behavior: NiFi is restarted, SSH command hang on

      This seems to be somehow related to SSH handling IO streams of process. Seems like detached NiFi java process does not close stdin/out/err (i do not know precisely) leading to sshd waiting for some input/output to come to client.

      I was able to do a quick&dirty fix in nifi.sh as follows:
      1. on existing nifi installation, in file /etc/init.d/nifi find the line

      (cd "${NIFI_HOME}" && ${sudo_cmd_prefix} "${JAVA}" -cp "${BOOTSTRAP_CLASSPATH}" -Xms12m -Xmx24m -Dorg.apache.nifi.bootstrap.config.file="${BOOTSTRAP_CONF}" org.apache.nifi.bootstrap.RunNiFi $@ &)
      

      its line number 214 (true branch of if [ "$1"] = "start"] condition).
      2. replace it by line:

      (cd "${NIFI_HOME}" && ${sudo_cmd_prefix} "${JAVA}" -cp "${BOOTSTRAP_CLASSPATH}" -Xms12m -Xmx24m -Dorg.apache.nifi.bootstrap.config.file="${BOOTSTRAP_CONF}" org.apache.nifi.bootstrap.RunNiFi $@ > /dev/null 2>&1 < /dev/null &)
      

      This simply redirects stdin from /dev/null to NiFi java process and redirects stdout/err to /dev/null letting SSH to close the session.

      After applying this fix, I am able to restart NiFi remotely using SSH.

      Use case for this scenario: When Flow Manager develop flow.xml.gz on localhost/testing environments, usually deployment to production environment is handled by jenkins/bamboo CI tools. These tools need to log in, upload new flow.xml.gz and restart NiFi. All remotely using SSH.

      If somebody can advice me where in the source code is this line of code located, I can prepare a pull request for this quick&dirty fix.
      But. Maybe we may want to go further and investigate what to do with IO streams inside Java...

      Attachments

        Issue Links

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            aldrin Aldrin Piri
            michal.klempa Michal Klempa
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment