2010-02-08 08:30:06 -05:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
# OPTIONS:
|
2013-12-15 14:29:11 -05:00
|
|
|
# -d: daemonize, start in the background
|
2010-02-08 08:30:06 -05:00
|
|
|
# -p <filename>: log the pid to a file (useful to kill it later)
|
|
|
|
|
|
|
|
# CONTROLLING STARTUP:
|
|
|
|
#
|
|
|
|
# This script relies on few environment variables to determine startup
|
|
|
|
# behavior, those variables are:
|
|
|
|
#
|
2011-03-30 15:03:24 -04:00
|
|
|
# ES_CLASSPATH -- A Java classpath containing everything necessary to run.
|
2010-06-07 11:20:07 -04:00
|
|
|
# JAVA_OPTS -- Additional arguments to the JVM for heap size, etc
|
|
|
|
# ES_JAVA_OPTS -- External Java Opts on top of the defaults set
|
2010-02-08 08:30:06 -05:00
|
|
|
#
|
2010-06-07 11:26:01 -04:00
|
|
|
#
|
|
|
|
# Optionally, exact memory values can be set using the following values, note,
|
2010-11-06 16:34:49 -04:00
|
|
|
# they can still be set using the `ES_JAVA_OPTS`. Sample format include "512m", and "10g".
|
2010-06-07 11:26:01 -04:00
|
|
|
#
|
2012-02-06 15:13:15 -05:00
|
|
|
# ES_HEAP_SIZE -- Sets both the minimum and maximum memory to allocate (recommended)
|
2010-06-07 11:26:01 -04:00
|
|
|
#
|
2010-02-08 08:30:06 -05:00
|
|
|
# As a convenience, a fragment of shell is sourced in order to set one or
|
|
|
|
# more of these variables. This so-called `include' can be placed in a
|
|
|
|
# number of locations and will be searched for in order. The lowest
|
|
|
|
# priority search path is the same directory as the startup script, and
|
|
|
|
# since this is the location of the sample in the project tree, it should
|
|
|
|
# almost work Out Of The Box.
|
|
|
|
#
|
|
|
|
# Any serious use-case though will likely require customization of the
|
|
|
|
# include. For production installations, it is recommended that you copy
|
|
|
|
# the sample to one of /usr/share/elasticsearch/elasticsearch.in.sh,
|
|
|
|
# /usr/local/share/elasticsearch/elasticsearch.in.sh, or
|
|
|
|
# /opt/elasticsearch/elasticsearch.in.sh and make your modifications there.
|
|
|
|
#
|
|
|
|
# Another option is to specify the full path to the include file in the
|
|
|
|
# environment. For example:
|
|
|
|
#
|
|
|
|
# $ ES_INCLUDE=/path/to/in.sh elasticsearch -p /var/run/es.pid
|
|
|
|
#
|
|
|
|
# Note: This is particularly handy for running multiple instances on a
|
|
|
|
# single installation, or for quick tests.
|
|
|
|
#
|
|
|
|
# If you would rather configure startup entirely from the environment, you
|
|
|
|
# can disable the include by exporting an empty ES_INCLUDE, or by
|
|
|
|
# ensuring that no include files exist in the aforementioned search list.
|
|
|
|
# Be aware that you will be entirely responsible for populating the needed
|
|
|
|
# environment variables.
|
|
|
|
|
2013-12-10 21:12:45 -05:00
|
|
|
|
|
|
|
# Maven will replace the project.name with elasticsearch below. If that
|
|
|
|
# hasn't been done, we assume that this is not a packaged version and the
|
|
|
|
# user has forgotten to run Maven to create a package.
|
|
|
|
IS_PACKAGED_VERSION='${project.name}'
|
|
|
|
if [ "$IS_PACKAGED_VERSION" != "elasticsearch" ]; then
|
|
|
|
cat >&2 << EOF
|
|
|
|
Error: You must build the project with Maven or download a pre-built package
|
|
|
|
before you can run Elasticsearch. See 'Building from Source' in README.textile
|
|
|
|
or visit http://www.elasticsearch.org/download to get a pre-built package.
|
|
|
|
EOF
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2011-04-17 11:59:58 -04:00
|
|
|
CDPATH=""
|
2010-02-08 08:30:06 -05:00
|
|
|
SCRIPT="$0"
|
|
|
|
|
|
|
|
# SCRIPT may be an arbitrarily deep series of symlinks. Loop until we have the concrete path.
|
|
|
|
while [ -h "$SCRIPT" ] ; do
|
|
|
|
ls=`ls -ld "$SCRIPT"`
|
|
|
|
# Drop everything prior to ->
|
|
|
|
link=`expr "$ls" : '.*-> \(.*\)$'`
|
|
|
|
if expr "$link" : '/.*' > /dev/null; then
|
|
|
|
SCRIPT="$link"
|
|
|
|
else
|
|
|
|
SCRIPT=`dirname "$SCRIPT"`/"$link"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
# determine elasticsearch home
|
|
|
|
ES_HOME=`dirname "$SCRIPT"`/..
|
|
|
|
|
|
|
|
# make ELASTICSEARCH_HOME absolute
|
2011-03-18 21:00:27 -04:00
|
|
|
ES_HOME=`cd "$ES_HOME"; pwd`
|
2010-02-08 08:30:06 -05:00
|
|
|
|
|
|
|
|
|
|
|
# If an include wasn't specified in the environment, then search for one...
|
|
|
|
if [ "x$ES_INCLUDE" = "x" ]; then
|
|
|
|
# Locations (in order) to use when searching for an include file.
|
|
|
|
for include in /usr/share/elasticsearch/elasticsearch.in.sh \
|
|
|
|
/usr/local/share/elasticsearch/elasticsearch.in.sh \
|
|
|
|
/opt/elasticsearch/elasticsearch.in.sh \
|
|
|
|
~/.elasticsearch.in.sh \
|
2014-10-22 12:37:09 -04:00
|
|
|
$ES_HOME/bin/elasticsearch.in.sh \
|
2013-09-17 02:14:23 -04:00
|
|
|
"`dirname "$0"`"/elasticsearch.in.sh; do
|
2011-03-18 21:00:27 -04:00
|
|
|
if [ -r "$include" ]; then
|
|
|
|
. "$include"
|
2010-02-08 08:30:06 -05:00
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
# ...otherwise, source the specified include.
|
2011-03-18 21:00:27 -04:00
|
|
|
elif [ -r "$ES_INCLUDE" ]; then
|
|
|
|
. "$ES_INCLUDE"
|
2010-02-08 08:30:06 -05:00
|
|
|
fi
|
|
|
|
|
2012-05-24 03:28:40 -04:00
|
|
|
if [ -x "$JAVA_HOME/bin/java" ]; then
|
2012-09-01 05:54:25 -04:00
|
|
|
JAVA="$JAVA_HOME/bin/java"
|
2012-05-24 03:28:40 -04:00
|
|
|
else
|
2013-12-03 04:23:40 -05:00
|
|
|
JAVA=`which java`
|
2013-07-15 10:01:07 -04:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -x "$JAVA" ]; then
|
|
|
|
echo "Could not find any executable java binary. Please install java in your PATH or set JAVA_HOME"
|
|
|
|
exit 1
|
2012-05-24 03:28:40 -04:00
|
|
|
fi
|
|
|
|
|
2011-03-18 21:00:27 -04:00
|
|
|
if [ -z "$ES_CLASSPATH" ]; then
|
2011-03-30 15:03:24 -04:00
|
|
|
echo "You must set the ES_CLASSPATH var" >&2
|
2010-02-08 08:30:06 -05:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Special-case path variables.
|
2011-03-18 21:00:27 -04:00
|
|
|
case `uname` in
|
2010-02-08 08:30:06 -05:00
|
|
|
CYGWIN*)
|
2011-03-30 15:03:24 -04:00
|
|
|
ES_CLASSPATH=`cygpath -p -w "$ES_CLASSPATH"`
|
2011-05-13 06:46:04 -04:00
|
|
|
ES_HOME=`cygpath -p -w "$ES_HOME"`
|
2010-02-08 08:30:06 -05:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
launch_service()
|
|
|
|
{
|
|
|
|
pidpath=$1
|
2013-12-15 14:29:11 -05:00
|
|
|
daemonized=$2
|
2010-02-08 08:30:06 -05:00
|
|
|
props=$3
|
2011-12-01 10:04:15 -05:00
|
|
|
es_parms="-Delasticsearch"
|
2010-02-08 08:30:06 -05:00
|
|
|
|
|
|
|
if [ "x$pidpath" != "x" ]; then
|
2011-12-20 22:28:28 -05:00
|
|
|
es_parms="$es_parms -Des.pidfile=$pidpath"
|
2010-02-08 08:30:06 -05:00
|
|
|
fi
|
|
|
|
|
2014-05-27 11:31:09 -04:00
|
|
|
# Make sure we dont use any predefined locale, as we check some exception message strings and rely on english language
|
|
|
|
# As those strings are created by the OS, they are dependant on the configured locale
|
|
|
|
LANG=en_US.UTF-8
|
|
|
|
LC_ALL=en_US.UTF-8
|
|
|
|
|
2014-01-06 15:58:46 -05:00
|
|
|
# The es-foreground option will tell Elasticsearch not to close stdout/stderr, but it's up to us not to daemonize.
|
2013-12-24 07:35:59 -05:00
|
|
|
if [ "x$daemonized" = "x" ]; then
|
2011-12-20 22:28:28 -05:00
|
|
|
es_parms="$es_parms -Des.foreground=yes"
|
2011-12-01 10:04:15 -05:00
|
|
|
exec "$JAVA" $JAVA_OPTS $ES_JAVA_OPTS $es_parms -Des.path.home="$ES_HOME" -cp "$ES_CLASSPATH" $props \
|
2014-01-06 15:58:46 -05:00
|
|
|
org.elasticsearch.bootstrap.Elasticsearch
|
2013-08-23 06:34:19 -04:00
|
|
|
# exec without running it in the background, makes it replace this shell, we'll never get here...
|
|
|
|
# no need to return something
|
2010-02-08 08:30:06 -05:00
|
|
|
else
|
2014-01-06 15:58:46 -05:00
|
|
|
# Startup Elasticsearch, background it, and write the pid.
|
2011-12-01 10:04:15 -05:00
|
|
|
exec "$JAVA" $JAVA_OPTS $ES_JAVA_OPTS $es_parms -Des.path.home="$ES_HOME" -cp "$ES_CLASSPATH" $props \
|
2014-01-06 15:58:46 -05:00
|
|
|
org.elasticsearch.bootstrap.Elasticsearch <&- &
|
2013-08-23 06:34:19 -04:00
|
|
|
return $?
|
2010-02-08 08:30:06 -05:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2013-12-16 05:30:10 -05:00
|
|
|
# Parse any long getopt options and put them into properties before calling getopt below
|
|
|
|
# Be dash compatible to make sure running under ubuntu works
|
|
|
|
ARGV=""
|
|
|
|
while [ $# -gt 0 ]
|
|
|
|
do
|
|
|
|
case $1 in
|
|
|
|
--*=*) properties="$properties -Des.${1#--}"
|
|
|
|
shift 1
|
|
|
|
;;
|
|
|
|
--*) properties="$properties -Des.${1#--}=$2"
|
|
|
|
shift 2
|
|
|
|
;;
|
|
|
|
*) ARGV="$ARGV $1" ; shift
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2010-02-08 08:30:06 -05:00
|
|
|
# Parse any command line options.
|
2013-12-24 12:21:26 -05:00
|
|
|
args=`getopt vdhp:D:X: $ARGV`
|
2010-02-08 08:30:06 -05:00
|
|
|
eval set -- "$args"
|
|
|
|
|
|
|
|
while true; do
|
2011-03-18 21:00:27 -04:00
|
|
|
case $1 in
|
2010-04-26 04:05:56 -04:00
|
|
|
-v)
|
2011-12-01 10:04:15 -05:00
|
|
|
"$JAVA" $JAVA_OPTS $ES_JAVA_OPTS $es_parms -Des.path.home="$ES_HOME" -cp "$ES_CLASSPATH" $props \
|
2010-04-26 04:05:56 -04:00
|
|
|
org.elasticsearch.Version
|
|
|
|
exit 0
|
|
|
|
;;
|
2010-02-08 08:30:06 -05:00
|
|
|
-p)
|
|
|
|
pidfile="$2"
|
|
|
|
shift 2
|
|
|
|
;;
|
2013-12-15 14:29:11 -05:00
|
|
|
-d)
|
|
|
|
daemonized="yes"
|
2010-02-08 08:30:06 -05:00
|
|
|
shift
|
|
|
|
;;
|
|
|
|
-h)
|
2013-12-15 14:29:11 -05:00
|
|
|
echo "Usage: $0 [-d] [-h] [-p pidfile]"
|
2010-02-08 08:30:06 -05:00
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
-D)
|
|
|
|
properties="$properties -D$2"
|
|
|
|
shift 2
|
|
|
|
;;
|
|
|
|
-X)
|
|
|
|
properties="$properties -X$2"
|
|
|
|
shift 2
|
|
|
|
;;
|
|
|
|
--)
|
|
|
|
shift
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
*)
|
2013-07-15 10:01:07 -04:00
|
|
|
echo "Error parsing argument $1!" >&2
|
2010-02-08 08:30:06 -05:00
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
# Start up the service
|
2013-12-15 14:29:11 -05:00
|
|
|
launch_service "$pidfile" "$daemonized" "$properties"
|
2010-02-08 08:30:06 -05:00
|
|
|
|
|
|
|
exit $?
|