This repository has been archived by the owner on Feb 17, 2023. It is now read-only.
forked from 2degrees/docker-solr4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolr
executable file
·73 lines (47 loc) · 1.51 KB
/
solr
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
#!/bin/bash
# Make Bash intolerant to errors
set -o nounset
set -o errexit
set -o pipefail
# ===== Configuration
JVM_MIN_HEAP_RATIO="0.5"
JVM_MAX_HEAP_RATIO="0.9"
# ===== Constants and functions
function multiply() {
local x="$1"
local y="$2"
awk -v "x=${x}" -v "y=${y}" 'BEGIN{ printf "%i" ,x * y }'
}
function get_container_memory_bytes() {
cgget -n --values-only --variable memory.limit_in_bytes /
}
function get_host_memory_bytes() {
free --bytes --total | tail --lines=1 | awk '{ print $2 }'
}
function is_container_memory_limited() {
(( $(get_container_memory_bytes) < $(get_host_memory_bytes) ))
}
function get_jvm_memory_cli_args() {
local cli_args
if is_container_memory_limited; then
local container_memory_bytes="$(get_container_memory_bytes)"
local min_heap_bytes="$(multiply "${container_memory_bytes}" "${JVM_MIN_HEAP_RATIO}" )"
local max_heap_bytes="$(multiply "${container_memory_bytes}" "${JVM_MAX_HEAP_RATIO}" )"
cli_args="-Xms${min_heap_bytes} -Xmx${max_heap_bytes}"
else
cli_args=""
fi
echo "${cli_args}"
}
# ===== Main
JAVA_EXTRA_ARGS="${@:1} $(get_jvm_memory_cli_args)"
cd "${JETTY_HOME_PATH}"
exec java \
-server \
-Djava.net.preferIPv4Stack=true \
-Dsolr.autoSoftCommit.maxTime=3000 \
-Djetty.home="${JETTY_HOME_PATH}" \
-Dsolr.solr.home="${SOLR_HOME_PATH}" \
-Dsolr.data.dir="${SOLR_INDICES_DIR_PATH}" \
${JAVA_EXTRA_ARGS} \
-jar "${SOLR_DISTRIBUTION_PATH}/example/start.jar"