summaryrefslogtreecommitdiff
path: root/system/elasticsearch/rc.elasticsearch
blob: 756f58acc0852704424ffd76bb590948417a32c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/sh
#
# /etc/rc.d/rc.elasticsearch -- startup script Slackware Linux for Elasticsearch
#
# Written by Daniel Romero <infoslack@gmail.com>.
#
# This script requires a 'elasticsearch' user/group to exist before running.
# The recommended UID/GID is 280. You can create these like so:
# groupadd -g 280 elasticsearch
# useradd -u 280 -g elasticsearch -s /bin/sh elasticsearch

set -e

# set params
PATH=/bin:/usr/bin:/sbin:/usr/sbin:$JAVA_HOME/bin:$JAVA_HOME/jre/bin
NAME=elasticsearch
DEFAULT=/etc/default/$NAME
ES_HOME=/usr/share/$NAME
ES_USER=$NAME
ES_GROUP=$NAME
LOG_DIR=/var/log/$NAME
DATA_DIR=/var/lib/$NAME
WORK_DIR=$DATA_DIR/data
CONF_DIR=/etc/$NAME
CONF_FILE=$CONF_DIR/elasticsearch.yml
PID_FILE=/var/run/$NAME.pid
DAEMON=$ES_HOME/bin/$NAME
MAX_OPEN_FILES=65535
DAEMON_OPTS="-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"

# overwrite settings from default file
if [ -f "$DEFAULT" ]; then
	. "$DEFAULT"
fi

# Check DAEMON exists
test -x $DAEMON || exit 0

case "$1" in
  start)
	  echo "Starting $NAME"
	  touch "$PID_FILE" && chown "$ES_USER":"$ES_GROUP" "$PID_FILE"
	  sudo -u $ES_USER sh -c "$DAEMON $DAEMON_OPTS"
	;;

  stop)
	  if [ -f "$PID_FILE" ]; then
      `cat $PID_FILE | xargs kill -9`
		  if [ $? -eq 1 ]; then
			  echo "$DESC is not running but pid file exists, cleaning up"
		  elif [ $? -eq 3 ]; then
			  PID="`cat $PID_FILE`"
			  echo "Failed to stop $NAME (pid $PID)"
			  exit 1
		  fi
		    rm -f "$PID_FILE"
	    else
		    echo "(not running)"
	  fi
	  echo "Stop $NAME"
	;;

  restart)
	  if [ -f "$PID_FILE" ]; then
		  $0 stop
		  sleep 1
	  fi
	  $0 start
	;;

  *)
	  echo "Usage: $0 {start|stop|restart}"
	  exit 1
	;;

esac
exit 0