#!/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() { checkpath -d -o $user:$group -m755 "$home_dir" || die checkpath -d -o $user:$group -m700 "$default_data_dir" || die checkpath -d -o $user:$group -m700 "$default_work_dir" || die checkpath -d "$default_script_dir" || die if yesno "$create_logs_dir"; then checkpath -d -o $user:$group -m755 "$default_logs_dir" || die fi if [ -n "$max_fd" ]; then ulimit -n "$max_fd" && einfo "Max open filedescriptors: $max_fd" return 0 fi }