3 # /etc/init.d/elasticsearch-<%= @name %> -- startup script for Elasticsearch
5 # Written by Miquel van Smoorenburg <miquels@cistron.nl>.
6 # Modified for Debian GNU/Linux by Ian Murdock <imurdock@gnu.ai.mit.edu>.
7 # Modified for Tomcat by Stefan Gybas <sgybas@debian.org>.
8 # Modified for Tomcat6 by Thierry Carrez <thierry.carrez@ubuntu.com>.
9 # Additional improvements by Jason Brittain <jason.brittain@mulesoft.com>.
10 # Modified by Nicolas Huray for Elasticsearch <nicolas.huray@gmail.com>.
13 # Provides: elasticsearch-<%= @name %>
14 # Required-Start: $network $remote_fs $named
15 # Required-Stop: $network $remote_fs $named
16 # Default-Start: 2 3 4 5
18 # Short-Description: Starts elasticsearch-<%= @name %>
19 # Description: Starts elasticsearch-<%= @name %> using start-stop-daemon
22 PATH=/bin:/usr/bin:/sbin:/usr/sbin
23 NAME=elasticsearch-<%= @name %>
24 DESC="Elasticsearch Server <%= @name %>"
25 DEFAULT=/etc/default/$NAME
27 if [ `id -u` -ne 0 ]; then
28 echo "You need root privileges to run this script"
33 . /lib/lsb/init-functions
35 if [ -r /etc/default/rcS ]; then
40 # The following variables can be overwritten in $DEFAULT
42 # Run Elasticsearch as this user ID and group ID
44 ES_GROUP=elasticsearch
46 # The first existing directory is used for JAVA_HOME (if JAVA_HOME is not defined in $DEFAULT)
47 JDK_DIRS="/usr/lib/jvm/java-7-oracle /usr/lib/jvm/java-7-openjdk /usr/lib/jvm/java-7-openjdk-amd64/ /usr/lib/jvm/java-7-openjdk-armhf /usr/lib/jvm/java-7-openjdk-i386/ /usr/lib/jvm/java-6-sun /usr/lib/jvm/java-6-openjdk /usr/lib/jvm/java-6-openjdk-amd64 /usr/lib/jvm/java-6-openjdk-armhf /usr/lib/jvm/java-6-openjdk-i386 /usr/lib/jvm/default-java"
49 # Look for the right JVM to use
50 for jdir in $JDK_DIRS; do
51 if [ -r "$jdir/bin/java" -a -z "${JAVA_HOME}" ]; then
57 # Directory where the Elasticsearch binary distribution resides
58 ES_HOME=/usr/share/$NAME
60 # Heap Size (defaults to 256m min, 1g max)
69 # Additional Java OPTS
72 # Maximum number of open files
75 # Maximum amount of locked memory
78 # Elasticsearch log directory
79 LOG_DIR=/var/log/$NAME
81 # Elasticsearch data directory
82 DATA_DIR=/var/lib/$NAME
84 # Elasticsearch work directory
87 # Elasticsearch configuration directory
90 # Elasticsearch configuration file (elasticsearch.yml)
91 CONF_FILE=$CONF_DIR/elasticsearch.yml
93 # Maximum number of VMA (Virtual Memory Areas) a process can own
96 # End of variables that can be overwritten in $DEFAULT
98 # overwrite settings from default file
99 if [ -f "$DEFAULT" ]; then
103 # Define other required variables
104 PID_FILE=/var/run/$NAME.pid
105 DAEMON=$ES_HOME/bin/elasticsearch
106 DAEMON_OPTS="-d -p $PID_FILE -Des.default.config=$CONF_FILE -Des.default.path.home=$ES_HOME -Des.default.path.logs=$LOG_DIR -Des.default.path.data=$DATA_DIR -Des.default.path.work=$WORK_DIR -Des.default.path.conf=$CONF_DIR"
109 export ES_HEAP_NEWSIZE
110 export ES_DIRECT_SIZE
114 # Check DAEMON exists
115 test -x $DAEMON || exit 0
118 if [ -x "$JAVA_HOME/bin/java" ]; then
119 JAVA="$JAVA_HOME/bin/java"
124 if [ ! -x "$JAVA" ]; then
125 echo "Could not find any executable java binary. Please install java in your PATH or set JAVA_HOME"
134 if [ -n "$MAX_LOCKED_MEMORY" -a -z "$ES_HEAP_SIZE" ]; then
135 log_failure_msg "MAX_LOCKED_MEMORY is set - ES_HEAP_SIZE must also be set"
139 log_daemon_msg "Starting $DESC"
141 pid=`pidofproc -p $PID_FILE elasticsearch`
142 if [ -n "$pid" ] ; then
143 log_begin_msg "Already running."
148 # Prepare environment
149 mkdir -p "$LOG_DIR" "$DATA_DIR" "$WORK_DIR" && chown "$ES_USER":"$ES_GROUP" "$LOG_DIR" "$DATA_DIR" "$WORK_DIR"
150 touch "$PID_FILE" && chown "$ES_USER":"$ES_GROUP" "$PID_FILE"
152 if [ -n "$MAX_OPEN_FILES" ]; then
153 ulimit -n $MAX_OPEN_FILES
156 if [ -n "$MAX_LOCKED_MEMORY" ]; then
157 ulimit -l $MAX_LOCKED_MEMORY
160 if [ -n "$MAX_MAP_COUNT" ]; then
161 sysctl -q -w vm.max_map_count=$MAX_MAP_COUNT
165 start-stop-daemon --start -b --user "$ES_USER" -c "$ES_USER" --pidfile "$PID_FILE" --exec $DAEMON -- $DAEMON_OPTS
169 log_daemon_msg "Stopping $DESC"
171 if [ -f "$PID_FILE" ]; then
172 start-stop-daemon --stop --pidfile "$PID_FILE" \
174 --retry=TERM/20/KILL/5 >/dev/null
175 if [ $? -eq 1 ]; then
176 log_progress_msg "$DESC is not running but pid file exists, cleaning up"
177 elif [ $? -eq 3 ]; then
178 PID="`cat $PID_FILE`"
179 log_failure_msg "Failed to stop $DESC (pid $PID)"
184 log_progress_msg "(not running)"
189 status_of_proc -p $PID_FILE elasticsearch elasticsearch && exit 0 || exit $?
191 restart|force-reload)
192 if [ -f "$PID_FILE" ]; then
199 log_success_msg "Usage: $0 {start|stop|restart|force-reload|status}"