-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
opensearch
executable file
·97 lines (88 loc) · 2.96 KB
/
opensearch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/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
unset KEYSTORE_PASSWORD
KEYSTORE_PASSWORD=
if [[ $CHECK_KEYSTORE = true ]] \
&& bin/opensearch-keystore has-passwd --silent
then
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
# 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 $?