summaryrefslogtreecommitdiff
path: root/app-misc/elasticsearch/files/elasticsearch.init.9
blob: 5e4f2a70f41dd5b8134d71bc93e81f8c1f5ed3f5 (plain)
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
#!/sbin/openrc-run

name="Elasticsearch"
description="Elasticsearch Server"

ES_INSTANCE=${RC_SVCNAME#*.}

if [ -n "${ES_INSTANCE}" ] && [ ${RC_SVCNAME} != "elasticsearch" ]; then
	ES_BASE_PATH="/var/lib/elasticsearch/${ES_INSTANCE}"
	CONF_DIR="/etc/elasticsearch/${ES_INSTANCE}"
	DEFAULT_LOG_DIR="/var/log/elasticsearch/${ES_INSTANCE}"
else
	ES_BASE_PATH="/var/lib/elasticsearch/_default"
	CONF_DIR="/etc/elasticsearch"
	DEFAULT_LOG_DIR="/var/log/elasticsearch/_default"
fi

ES_HOME=${ES_HOME:="/usr/share/elasticsearch"}
ES_USER=${ES_USER:="elasticsearch"}
ES_GROUP=${ES_GROUP:="elasticsearch"}
ES_STARTUP_SLEEP_TIME=${ES_STARTUP_TIME:=5}
ES_JAVA_HOME=${ES_JAVA_HOME:=$(java-config -g JAVA_HOME)}
MAX_OPEN_FILES=${MAX_OPEN_FILES:=65536}
MAX_MAP_COUNT=${MAX_MAP_COUNT:=262144}

DATA_DIR=${DATA_DIR:="${ES_BASE_PATH}/data"}
LOG_DIR=${LOG_DIR:="${DEFAULT_LOG_DIR}"}

if [ -f "${CONF_DIR}/elasticsearch.in.sh" ]; then
    ES_INCLUDE="${CONF_DIR}/elasticsearch.in.sh"
fi

export ES_INCLUDE
export ES_JAVA_HOME
export ES_JAVA_OPTS
export ES_JVM_OPTIONS
export ES_STARTUP_SLEEP_TIME
export ES_PATH_CONF="${CONF_DIR}"

pidfile="/run/elasticsearch/${RC_SVCNAME}.pid"

command="/usr/share/elasticsearch/bin/elasticsearch"
command_args="-Epath.logs=${LOG_DIR} -Epath.data=${DATA_DIR}"
command_args_background="--daemonize --pidfile=${pidfile}"
command_user="${ES_USER}:${ES_GROUP}"
required_files="${CONF_DIR}/elasticsearch.yml"
retry="TERM/30/KILL/30"

depend() {
	use net
}

start_pre() {
	if [ -n "${MAX_MAP_COUNT}" -a -f /proc/sys/vm/max_map_count ]; then
		sysctl -q -w vm.max_map_count=${MAX_MAP_COUNT}
	fi

	checkpath -d -o "${ES_USER}:${ES_GROUP}" -m750 "/var/lib/elasticsearch"
	checkpath -d -o "${ES_USER}:${ES_GROUP}" -m750 "/var/log/elasticsearch"
	checkpath -d -o "${ES_USER}:${ES_GROUP}" -m750 "/run/elasticsearch"
	checkpath -d -o "${ES_USER}:${ES_GROUP}" -m750 "${ES_HOME}/plugins"
	checkpath -d -o "${ES_USER}:${ES_GROUP}" -m750 "${ES_BASE_PATH}"
	checkpath -d -o "${ES_USER}:${ES_GROUP}" -m750 "${LOG_DIR}"

	# fails to start without keystore
	if [ ! -f "${CONF_DIR}/elasticsearch.keystore" ]; then
		"${ES_HOME}/bin/elasticsearch-keystore" create
	else
		"${ES_HOME}/bin/elasticsearch-keystore" upgrade
	fi
}