#!/bin/sh
#
# This file is managed via PUPPET

daemon="/usr/local/elasticsearch/bin/elasticsearch"
daemon_flags="-d -<%= opt_flag %>default.path.conf=/etc/elasticsearch/<%= @resource[:instance] %> -p <%= @resource[:pid_dir] %>/elasticsearch-<%= @resource[:instance] %>.pid"
daemon_user="_elasticsearch"

. /etc/rc.d/rc.subr

pexp="$(/usr/local/bin/javaPathHelper -c elasticsearch) .*org.elasticsearch.bootstrap.Elasticsearch.*"

rc_reload=NO

rc_start() {
	${rcexec} \
		"ES_INCLUDE=\"/etc/elasticsearch/elasticsearch.in.sh\" \
		"ES_JVM_OPTIONS=\"/etc/elasticsearch/<%= @resource[:instance] %>/jvm.options\"" \
		JAVA_HOME=\"$(/usr/local/bin/javaPathHelper -h elasticsearch)\" \
		${daemon} ${daemon_flags}"
}

rc_pre() {
	install -d -o _elasticsearch <%= @resource[:pid_dir] %>
}

rc_cmd $1
