Uploaded image for project: 'Bitbucket Server'
  1. Bitbucket Server
  2. BSERV-12519

Bundled Elasticsearch unable to start unless JAVA_HOME is declared

    XMLWordPrintable

Details

    Description

      Issue Summary

      After a recent update to Elasticsearch 7 in Bitbucket 7.1.0, the default elasticsearch-env file within the directory $BITBUCKET_INSTALL/elasticsearch/bin has changed, making it so that the bundled Elasticsearch instance will not start up unless the environment variable JAVA_HOME has been set. This is because Elasticsearch's new backup Java location, if JAVA_HOME is not detected, is a bundled JDK that isn't actually present at $ES_HOME/jdk/bin/java.

      Steps to Reproduce

      1. Install or upgrade to Bitbucket 7.1+
      2. Ensure that the JAVA_HOME environment variable has not been set
      3. Attempt to start up Bitbucket and Elasticsearch by manually executing the file $BITBUCKET_INSTALL/bin/start-bitbucket.sh

      Expected Results

      Both Bitbucket and Elasticsearch use the bundled JRE located at $BITBUCKET_INSTALL/jre

      Actual Results

      The startup script successfully launches Bitbucket, but on attempting to launch Elasticsearch the following error is thrown in the console:

      could not find java in bundled jdk at /opt/app/bitbucket-7.4.0/elasticsearch/jdk/bin/java
      There was a problem starting bundled Elasticsearch
      

      In previous versions of Elasticsearch, on not detecting JAVA_HOME it instead used the command which java to find an alternative Java location. However, in the later versions of this elasticsearch-env file the logic there uses a static location based on the $ES_HOME:

      # now set the path to java
      if [ ! -z "$JAVA_HOME" ]; then
        JAVA="$JAVA_HOME/bin/java"
        JAVA_TYPE="JAVA_HOME"
      else
        if [ "$(uname -s)" = "Darwin" ]; then
          # macOS has a different structure
          JAVA="$ES_HOME/jdk.app/Contents/Home/bin/java"
        else
          JAVA="$ES_HOME/jdk/bin/java"
        fi
        JAVA_TYPE="bundled jdk"
      fi
      

      Workaround

      Set the environment variable JAVA_HOME to point to either the standard Bitbucket bundled JRE, or the Java home of a supported Java version.

      Alternatively, it's also possible to modify the logic in the file $BITBUCKET_INSTALL/elasticsearch/bin/elasticsearch-env to use a different/correct Java location. However, it's important to note that any changes to this file will be overwritten on performing an upgrade of Bitbucket and these changes will then need to be reapplied.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              eslaughter@atlassian.com Evan Slaughter
              Votes:
              8 Vote for this issue
              Watchers:
              20 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Backbone Issue Sync