Redhat start script updates

This commit is contained in:
Dale McDiarmid 2017-01-17 11:21:18 +00:00
parent 42c84e07a2
commit b2efa703da

View file

@ -32,16 +32,22 @@ if [ -f /etc/rc.d/init.d/functions ]; then
fi fi
# Sets the default values for elasticsearch variables used in this script # Sets the default values for elasticsearch variables used in this script
ES_USER="elasticsearch" ES_USER="{{es_user}}"
ES_GROUP="elasticsearch" ES_GROUP="{{es_group}}"
ES_HOME="/usr/share/elasticsearch" ES_HOME="{{es_home}}"
MAX_OPEN_FILES=65535 {% if es_max_open_files is defined %}
MAX_MAP_COUNT=262144 MAX_OPEN_FILES={{es_max_open_files}}
LOG_DIR="/var/log/elasticsearch" {% endif %}
DATA_DIR="/var/lib/elasticsearch" # Maximum number of VMA (Virtual Memory Areas) a process can own
CONF_DIR="/etc/elasticsearch" {% if es_max_map_count is defined %}
MAX_MAP_COUNT={{es_max_map_count}}
{% endif %}
PID_DIR="/var/run/elasticsearch" LOG_DIR="{{log_dir}}"
DATA_DIR={{ data_dirs | array_to_str }}
CONF_DIR="{{conf_dir}}"
PID_DIR="{{pid_dir}}"
# Source the default env file # Source the default env file
ES_ENV_FILE="{{instance_default_file}}" ES_ENV_FILE="{{instance_default_file}}"
@ -56,16 +62,24 @@ if [ ! -z "$CONF_FILE" ]; then
fi fi
exec="$ES_HOME/bin/elasticsearch" exec="$ES_HOME/bin/elasticsearch"
prog="elasticsearch" prog="{{es_instance_name}}_{{default_file | basename}}"
pidfile="$PID_DIR/${prog}.pid" pidfile="$PID_DIR/${prog}.pid"
export ES_HEAP_SIZE
export ES_HEAP_NEWSIZE
export ES_DIRECT_SIZE
export ES_JAVA_OPTS export ES_JAVA_OPTS
export ES_GC_LOG_FILE
export ES_STARTUP_SLEEP_TIME
export JAVA_HOME export JAVA_HOME
export ES_INCLUDE
export ES_JVM_OPTIONS
export ES_STARTUP_SLEEP_TIME
# export unsupported variables so bin/elasticsearch can reject them and inform the user these are unsupported
if test -n "$ES_MIN_MEM"; then export ES_MIN_MEM; fi
if test -n "$ES_MAX_MEM"; then export ES_MAX_MEM; fi
if test -n "$ES_HEAP_SIZE"; then export ES_HEAP_SIZE; fi
if test -n "$ES_HEAP_NEWSIZE"; then export ES_HEAP_NEWSIZE; fi
if test -n "$ES_DIRECT_SIZE"; then export ES_DIRECT_SIZE; fi
if test -n "$ES_USE_IPV4"; then export ES_USE_IPV4; fi
if test -n "$ES_GC_OPTS"; then export ES_GC_OPTS; fi
if test -n "$ES_GC_LOG_FILE"; then export ES_GC_LOG_FILE; fi
lockfile=/var/lock/subsys/$prog lockfile=/var/lock/subsys/$prog
@ -74,6 +88,11 @@ if [ -n $USER ] && [ -z $ES_USER ] ; then
ES_USER=$USER ES_USER=$USER
fi fi
if [ ! -x "$exec" ]; then
echo "The elasticsearch startup script does not exists or it is not executable, tried: $exec"
exit 1
fi
checkJava() { checkJava() {
if [ -x "$JAVA_HOME/bin/java" ]; then if [ -x "$JAVA_HOME/bin/java" ]; then
JAVA="$JAVA_HOME/bin/java" JAVA="$JAVA_HOME/bin/java"
@ -90,12 +109,7 @@ checkJava() {
start() { start() {
checkJava checkJava
[ -x $exec ] || exit 5 [ -x $exec ] || exit 5
{% if es_version | version_compare('5.0', '<') %}
if [ -n "$MAX_LOCKED_MEMORY" -a -z "$ES_HEAP_SIZE" ]; then
echo "MAX_LOCKED_MEMORY is set - ES_HEAP_SIZE must also be set"
return 7
fi
{% endif %}
if [ -n "$MAX_OPEN_FILES" ]; then if [ -n "$MAX_OPEN_FILES" ]; then
ulimit -n $MAX_OPEN_FILES ulimit -n $MAX_OPEN_FILES
fi fi
@ -105,7 +119,6 @@ start() {
if [ -n "$MAX_MAP_COUNT" -a -f /proc/sys/vm/max_map_count ]; then if [ -n "$MAX_MAP_COUNT" -a -f /proc/sys/vm/max_map_count ]; then
sysctl -q -w vm.max_map_count=$MAX_MAP_COUNT sysctl -q -w vm.max_map_count=$MAX_MAP_COUNT
fi fi
export ES_GC_LOG_FILE
# Ensure that the PID_DIR exists (it is cleaned at OS startup time) # Ensure that the PID_DIR exists (it is cleaned at OS startup time)
if [ -n "$PID_DIR" ] && [ ! -e "$PID_DIR" ]; then if [ -n "$PID_DIR" ] && [ ! -e "$PID_DIR" ]; then
@ -118,11 +131,7 @@ start() {
cd $ES_HOME cd $ES_HOME
echo -n $"Starting $prog: " echo -n $"Starting $prog: "
# if not running, start it up here, usually something like "daemon $exec" # if not running, start it up here, usually something like "daemon $exec"
{% if es_version | version_compare('5.0', '<') %} daemon --user $ES_USER --pidfile $pidfile $exec -p $pidfile -d -Edefault.path.logs=$LOG_DIR -Edefault.path.data=$DATA_DIR -Edefault.path.conf=$CONF_DIR
daemon --user $ES_USER --pidfile $pidfile $exec -p $pidfile -d -Des.default.path.home=$ES_HOME -Des.default.path.logs=$LOG_DIR -Des.default.path.data=$DATA_DIR -Des.default.path.conf=$CONF_DIR
{% else %}
daemon --user $ES_USER --pidfile $pidfile $exec -p $pidfile -d -Edefault.path.home=$ES_HOME -Edefault.path.logs=$LOG_DIR -Edefault.path.data=${DATA_DIR} -Edefault.path.conf=$CONF_DIR
{% endif %}
retval=$? retval=$?
echo echo
[ $retval -eq 0 ] && touch $lockfile [ $retval -eq 0 ] && touch $lockfile