aboutsummaryrefslogtreecommitdiffstats
path: root/community/elasticsearch/elasticsearch.initd
blob: 91dd6809beb5dcc2ce29cb312926d8008e41f1ad (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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/sbin/openrc-run

description="A Distributed RESTful Search Engine."

instance_name="${SVCNAME#elasticsearch.}"
instance_name="${instance_name/elasticsearch/_default}"

name="Elasticsearch"
[ "$instance_name" != "_default" ] && name="$name ($instance_name)"

: ${user:="elastico"}
: ${group:="$(id -gn $user)"}
: ${java_heap_size:="256"}

: ${conf_dir:="/etc/elasticsearch/${instance_name#_default}"}
: ${home_dir:="/var/lib/elasticsearch/$instance_name"}
: ${default_data_dir:="$home_dir/data"}
: ${default_plugins_dir:="$home_dir/plugins"}
: ${default_logs_dir:="/var/log/elasticsearch/${instance_name#_default}"}
: ${default_script_dir:="$conf_dir/scripts"}
: ${default_work_dir:="/var/tmp/elasticsearch/$instance_name"}
: ${create_logs_dir:="yes"}

java_opts="
	-server
	-XX:+DisableExplicitGC
	-Djava.awt.headless=true
	-Dfile.encoding=utf-8
	-Xms${java_heap_size}M -Xmx${java_heap_size}M
	${java_max_direct_mem_size:+"-XX:MaxDirectMemorySize=$java_max_direct_mem_size"}
	$java_opts"

lib_dir="/usr/share/java/elasticsearch/lib"
classpath="$lib_dir/elasticsearch-@@ES_VERSION@@.jar:$lib_dir/*"

command="java"
command_args="
	$java_opts
	-Des.path.conf='$conf_dir'
	-Des.path.home='$home_dir'
	-Des.default.path.data='$default_data_dir'
	-Des.default.path.plugins='$default_plugins_dir'
	-Des.default.path.work='$default_work_dir'
	-Des.default.path.logs='$default_logs_dir'
	-Des.default.path.script='$default_script_dir'
	-cp $classpath
	org.elasticsearch.bootstrap.Elasticsearch start
	$elastic_opts"
command_background="yes"

start_stop_daemon_args="
	--interpreted
	--chdir '$home_dir'
	--user $user:$group"
pidfile="/run/$SVCNAME.pid"
retry="TERM/20/KILL/5"

required_files="$conf_dir/elasticsearch.yml $conf_dir/logging.yml"

depend() {
	use net
}

start_pre() {
	local dir

	# Note: checkpath doesn't create intermediate directories.
	for dir in "$home_dir" "$default_data_dir" "$default_work_dir" "$default_script_dir"; do
		mkdir -p "$(dirname "$dir")"
	done

	checkpath -d -o $user:$group -m755 "$home_dir"
	checkpath -d -o $user:$group -m700 "$default_data_dir"
	checkpath -d -o $user:$group -m700 "$default_work_dir"
	checkpath -d "$default_script_dir"

	if yesno "$create_logs_dir"; then
		mkdir -p "$default_logs_dir"
		checkpath -d -o $user:$group -m755 "$default_logs_dir"
	fi

	if [ -n "$max_fd" ]; then
		ulimit -n "$max_fd" && einfo "Max open filedescriptors: $max_fd"
		return 0
	fi
}