textproc/elasticsearch5: rc script improvement

- Fix behavior with multiple profiles
- Correctly handle the individual config dirs
- Prevent thundering herd at shutdown by using wait_for_pids

Approved by:	maintainer
MFH:		2018Q1
This commit is contained in:
Mark Felder 2018-02-22 14:13:30 +00:00
parent bc4b221c89
commit ec3f9f13c1
Notes: svn2git 2021-03-31 03:12:20 +00:00
svn path=/head/; revision=462590
3 changed files with 28 additions and 48 deletions

View file

@ -3,7 +3,7 @@
PORTNAME= elasticsearch
PORTVERSION= 5.3.0
PORTREVISION= 1
PORTREVISION= 2
CATEGORIES= textproc java devel
MASTER_SITES= https://artifacts.elastic.co/downloads/${PORTNAME}/ \
http://mirrors.rit.edu/zi/

View file

@ -15,7 +15,7 @@
# Set it to required username.
# elasticsearch_group (group): Set to elasticsearch by default.
# Set it to required group.
# elasticsearch_config (path): Set to /usr/local/etc/elasticsearch/elasticsearch.yml by default.
# elasticsearch_config (path): Set to %%PREFIX%%/etc/elasticsearch/elasticsearch.yml by default.
# Set it to the config file location.
# elasticsearch_tmp (path): Set to /var/tmp/elasticsearch by default.
# Set it to the path to be used for temp files.
@ -27,31 +27,30 @@ rcvar=elasticsearch_enable
load_rc_config ${name}
: ${elasticsearch_enable:="NO"}
: ${elasticsearch_user:=%%SEARCHUSER%%}
: ${elasticsearch_group:=%%SEARCHGROUP%%}
: ${elasticsearch_config:="%%PREFIX%%/etc/elasticsearch"}
: ${elasticsearch_tmp:="/var/tmp/elasticsearch"}
: ${elasticsearch_enable:=NO}
: ${elasticsearch_user=elasticsearch}
: ${elasticsearch_group=elasticsearch}
: ${elasticsearch_config=%%PREFIX%%/etc/elasticsearch}
: ${elasticsearch_tmp=/var/tmp/elasticsearch}
required_files="${elasticsearch_config}/elasticsearch.yml"
_pidprefix="/var/run/elasticsearch"
pidfile="${_pidprefix}.pid"
_pidprefix=/var/run/elasticsearch
pidfile=${_pidprefix}.pid
extra_commands="console status"
console_cmd="elasticsearch_console"
start_precmd="elasticsearch_precmd"
status_cmd="elasticsearch_status"
stop_cmd="elasticsearch_stop"
command="%%PREFIX%%/lib/elasticsearch/bin/elasticsearch"
command_args="-d --pidfile=${pidfile}"
console_cmd=elasticsearch_console
start_precmd=elasticsearch_precmd
status_cmd=elasticsearch_status
stop_cmd=elasticsearch_stop
command=%%PREFIX%%/lib/elasticsearch/bin/elasticsearch
command_args="-d --pidfile=${pidfile} -Epath.conf=${elasticsearch_config}"
elasticsearch_precmd()
{
touch ${pidfile}
chown ${elasticsearch_user}:${elasticsearch_group} ${pidfile}
/usr/bin/install -d -o ${elasticsearch_user} -g ${elasticsearch_group} -m 750 ${elasticsearch_tmp}
/usr/bin/install -d -o ${elasticsearch_user} -g ${elasticsearch_group} -m 750 /var/db/elasticsearch
/usr/bin/install -d -o ${elasticsearch_user} -g ${elasticsearch_group} -m 750 /var/log/elasticsearch
/usr/bin/install -o ${elasticsearch_user} -g ${elasticsearch_group} /dev/null ${pidfile}
/usr/bin/install -d -o ${elasticsearch_user} -g ${elasticsearch_group} -m 755 ${elasticsearch_tmp}
/usr/bin/install -d -o ${elasticsearch_user} -g ${elasticsearch_group} -m 755 /var/db/elasticsearch
/usr/bin/install -d -o ${elasticsearch_user} -g ${elasticsearch_group} -m 755 /var/log/elasticsearch
}
elasticsearch_console()
@ -60,7 +59,6 @@ elasticsearch_console()
run_rc_command "start"
}
elasticsearch_stop()
{
rc_pid=$(elasticsearch_check_pidfile $pidfile)
@ -72,7 +70,8 @@ elasticsearch_stop()
fi
echo "Stopping ${name}."
kill ${rc_pid} 2> /dev/null
kill $sig_stop ${rc_pid}
wait_for_pids ${rc_pid}
}
elasticsearch_status()
@ -102,15 +101,13 @@ elasticsearch_check_pidfile()
debug "pid file ($_pidfile): no pid in file."
return
fi
if [ -n "`%%LOCALBASE%%/bin/jps -l | grep -e "^$_pid"`" ]; then
if [ -n "`%%PREFIX%%/bin/jps -l | grep -e "^$_pid"`" ]; then
echo -n $_pid
fi
}
if [ -n "$2" ]; then
profile="$2"
if [ "x${elasticsearch_profiles}" != "x" ]; then
pidfile="${_pidprefix}.${profile}.pid"
command_args="-d --pidfile=${pidfile}"
eval elasticsearch_config="\${elasticsearch_${profile}_config:-}"
if [ "x${elasticsearch_config}" = "x" ]; then
echo "You must define a configuration (elasticsearch_${profile}_config)"
@ -120,6 +117,11 @@ if [ -n "$2" ]; then
required_files="${elasticsearch_config}/jvm.options"
eval elasticsearch_enable="\${elasticsearch_${profile}_enable:-${elasticsearch_enable}}"
eval elasticsearch_tmp="\${elasticsearch_${profile}_args:-${elasticsearch_tmp}}"
pidfile="${_pidprefix}.${profile}.pid"
if [ -e ${elasticsearch_config}/jvm.options ]; then
export ES_JVM_OPTIONS=${elasticsearch_config}/jvm.options
fi
command_args="-d --pidfile=${pidfile} -Epath.conf=${elasticsearch_config}"
else
echo "$0: extra argument ignored"
fi
@ -147,7 +149,7 @@ else
;;
esac
echo "===> elasticsearch profile: ${profile}"
/usr/local/etc/rc.d/elasticsearch $1 ${profile}
%%PREFIX%%/etc/rc.d/elasticsearch $1 ${profile}
retcode="$?"
if [ "0${retcode}" -ne 0 ]; then
failed="${profile} (${retcode}) ${failed:-}"

View file

@ -1,22 +0,0 @@
--- bin/elasticsearch.in.sh.orig 2016-11-24 10:05:27 UTC
+++ bin/elasticsearch.in.sh
@@ -1,5 +1,19 @@
#!/bin/bash
+if [ `uname -o` == "FreeBSD" ]; then
+ . /etc/rc.subr
+ load_rc_config elasticsearch
+ ES_MIN_MEM=${elasticsearch_min_mem}
+ ES_MAX_MEM=${elasticsearch_max_mem}
+ ES_HEAP_NEW_SIZE=${elasticsearch_heap_newsize}
+ ES_DIRECT_SIZE=${elasticsearch_direct_size}
+ ES_USE_IPV4=${elasticsearch_use_ipv4}
+ ES_GC_OPTS=${elasticsearch_gc_opts}
+ ES_GC_LOG_FILE=${elasticsearch_gc_logfile}
+ ES_JAVA_OPTS="$ES_JAVA_OPTS -Des.path.conf=${elasticsearch_config:="/usr/local/etc/elasticsearch"}"
+ PATH=${PATH}:/usr/local/bin
+fi
+
# check in case a user was using this mechanism
if [ "x$ES_CLASSPATH" != "x" ]; then
cat >&2 << EOF