HEX
Server: nginx/1.24.0
System: Linux nowruzgan 6.8.0-57-generic #59-Ubuntu SMP PREEMPT_DYNAMIC Sat Mar 15 17:40:59 UTC 2025 x86_64
User: babak (1000)
PHP: 8.3.6
Disabled: NONE
Upload Files
File: //usr/share/opensearch/bin/opensearch
#!/usr/bin/env bash

# CONTROLLING STARTUP:
#
# This script relies on a few environment variables to determine startup
# behavior, those variables are:
#
#   OPENSEARCH_PATH_CONF -- Path to config directory
#   OPENSEARCH_JAVA_OPTS -- External Java Opts on top of the defaults set
#
# Optionally, exact memory values can be set using the `OPENSEARCH_JAVA_OPTS`. Example
# values are "512m", and "10g".
#
#   OPENSEARCH_JAVA_OPTS="-Xms8g -Xmx8g" ./bin/opensearch

set -e -o pipefail

source "`dirname "$0"`"/opensearch-env

CHECK_KEYSTORE=true
DAEMONIZE=false
for option in "$@"; do
  case "$option" in
    -h|--help|-V|--version)
      CHECK_KEYSTORE=false
      ;;
    -d|--daemonize)
      DAEMONIZE=true
      ;;
  esac
done

if [ -z "$OPENSEARCH_TMPDIR" ]; then
  OPENSEARCH_TMPDIR=`"$JAVA" "$XSHARE" -cp "$OPENSEARCH_CLASSPATH" org.opensearch.tools.launchers.TempDirectory`
fi

# get keystore password before setting java options to avoid
# conflicting GC configurations for the keystore tools
if [[ $CHECK_KEYSTORE = true ]] \
    && bin/opensearch-keystore has-passwd --silent
then
  if [[ ! -z "${KEYSTORE_PASSWORD}" ]]; then
    echo "Using value of KEYSTORE_PASSWORD from the environment"
  else
    if ! read -s -r -p "OpenSearch keystore password: " KEYSTORE_PASSWORD ; then
      echo "Failed to read keystore password on console" 1>&2
      exit 1
    fi
  fi
fi

# The JVM options parser produces the final JVM options to start OpenSearch.
# It does this by incorporating JVM options in the following way:
#   - first, system JVM options are applied (these are hardcoded options in the
#     parser)
#   - second, JVM options are read from jvm.options and jvm.options.d/*.options
#   - third, JVM options from OPENSEARCH_JAVA_OPTS are applied
#   - fourth, ergonomic JVM options are applied
OPENSEARCH_JAVA_OPTS=`export OPENSEARCH_TMPDIR; "$JAVA" "$XSHARE" -cp "$OPENSEARCH_CLASSPATH" org.opensearch.tools.launchers.JvmOptionsParser "$OPENSEARCH_PATH_CONF"`

# manual parsing to find out, if process should be detached
if [[ $DAEMONIZE = false ]]; then
  exec \
    "$JAVA" \
    "$XSHARE" \
    $OPENSEARCH_JAVA_OPTS \
    -Dopensearch.path.home="$OPENSEARCH_HOME" \
    -Dopensearch.path.conf="$OPENSEARCH_PATH_CONF" \
    -Dopensearch.distribution.type="$OPENSEARCH_DISTRIBUTION_TYPE" \
    -Dopensearch.bundled_jdk="$OPENSEARCH_BUNDLED_JDK" \
    -cp "$OPENSEARCH_CLASSPATH" \
    org.opensearch.bootstrap.OpenSearch \
    "$@" <<<"$KEYSTORE_PASSWORD"
else
  exec \
    "$JAVA" \
    "$XSHARE" \
    $OPENSEARCH_JAVA_OPTS \
    -Dopensearch.path.home="$OPENSEARCH_HOME" \
    -Dopensearch.path.conf="$OPENSEARCH_PATH_CONF" \
    -Dopensearch.distribution.type="$OPENSEARCH_DISTRIBUTION_TYPE" \
    -Dopensearch.bundled_jdk="$OPENSEARCH_BUNDLED_JDK" \
    -cp "$OPENSEARCH_CLASSPATH" \
    org.opensearch.bootstrap.OpenSearch \
    "$@" \
    <<<"$KEYSTORE_PASSWORD" &
  retval=$?
  pid=$!
  [ $retval -eq 0 ] || exit $retval
  if [ ! -z "$OPENSEARCH_STARTUP_SLEEP_TIME" ]; then
    sleep $OPENSEARCH_STARTUP_SLEEP_TIME
  fi
  if ! ps -p $pid > /dev/null ; then
    exit 1
  fi
  exit 0
fi

exit $?