]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/elasticsearch/templates/etc/init.d/elasticsearch.RedHat.erb
Add new module elasticsearch for listsearch
[dsa-puppet.git] / 3rdparty / modules / elasticsearch / templates / etc / init.d / elasticsearch.RedHat.erb
1 #!/bin/sh
2 #
3 # elasticsearch<%= @name %> <summary>
4 #
5 # chkconfig:   2345 80 20
6 # description: Starts and stops a single elasticsearch instance on this system
7 #
8
9 ### BEGIN INIT INFO
10 # Provides: Elasticsearch-<%= @name %>
11 # Required-Start: $network $named
12 # Required-Stop: $network $named
13 # Default-Start: 2 3 4 5
14 # Default-Stop: 0 1 6
15 # Short-Description: This service manages the elasticsearch daemon
16 # Description: Elasticsearch is a very scalable, schema-free and high-performance search solution supporting multi-tenancy and near realtime search.
17 ### END INIT INFO
18
19 #
20 # init.d / servicectl compatibility (openSUSE)
21 #
22 if [ -f /etc/rc.status ]; then
23     . /etc/rc.status
24     rc_reset
25 fi
26
27 #
28 # Source function library.
29 #
30 if [ -f /etc/rc.d/init.d/functions ]; then
31     . /etc/rc.d/init.d/functions
32 fi
33
34 exec="/usr/share/elasticsearch/bin/elasticsearch"
35 prog="elasticsearch-<%= @name %>"
36 pidfile=/var/run/elasticsearch/${prog}.pid
37
38 [ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
39
40 export ES_HEAP_SIZE
41 export ES_HEAP_NEWSIZE
42 export ES_DIRECT_SIZE
43 export ES_JAVA_OPTS
44 export ES_CLASSPATH
45
46 lockfile=/var/lock/subsys/$prog
47
48 # backwards compatibility for old config sysconfig files, pre 0.90.1
49 if [ -n $USER ] && [ -z $ES_USER ] ; then
50    ES_USER=$USER
51 fi
52
53 checkJava() {
54     if [ -x "$JAVA_HOME/bin/java" ]; then
55         JAVA="$JAVA_HOME/bin/java"
56     else
57         JAVA=`which java`
58     fi
59
60     if [ ! -x "$JAVA" ]; then
61         echo "Could not find any executable java binary. Please install java in your PATH or set JAVA_HOME"
62         exit 1
63     fi
64 }
65
66 start() {
67     checkJava
68     [ -x $exec ] || exit 5
69     [ -f $CONF_FILE ] || exit 6
70     if [ -n "$MAX_LOCKED_MEMORY" -a -z "$ES_HEAP_SIZE" ]; then
71         echo "MAX_LOCKED_MEMORY is set - ES_HEAP_SIZE must also be set"
72         return 7
73     fi
74     if [ -n "$MAX_OPEN_FILES" ]; then
75         ulimit -n $MAX_OPEN_FILES
76     fi
77     if [ -n "$MAX_LOCKED_MEMORY" ]; then
78         ulimit -l $MAX_LOCKED_MEMORY
79     fi
80     if [ -n "$MAX_MAP_COUNT" ]; then
81         sysctl -q -w vm.max_map_count=$MAX_MAP_COUNT
82     fi
83     if [ -n "$WORK_DIR" ]; then
84         mkdir -p "$WORK_DIR"
85         chown "$ES_USER":"$ES_GROUP" "$WORK_DIR"
86     fi
87     echo -n $"Starting $prog: "
88     # if not running, start it up here, usually something like "daemon $exec"
89     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.work=$WORK_DIR -Des.default.path.conf=$CONF_DIR
90     retval=$?
91     echo
92     [ $retval -eq 0 ] && touch $lockfile
93     return $retval
94 }
95
96 stop() {
97     echo -n $"Stopping $prog: "
98     # stop it here, often "killproc $prog"
99     killproc -p $pidfile -d 20 $prog
100     retval=$?
101     echo
102     [ $retval -eq 0 ] && rm -f $lockfile
103     return $retval
104 }
105
106 restart() {
107     stop
108     start
109 }
110
111 reload() {
112     restart
113 }
114
115 force_reload() {
116     restart
117 }
118
119 rh_status() {
120     # run checks to determine if the service is running or use generic status
121     status -p $pidfile $prog
122 }
123
124 rh_status_q() {
125     rh_status >/dev/null 2>&1
126 }
127
128
129 case "$1" in
130     start)
131         rh_status_q && exit 0
132         $1
133         ;;
134     stop)
135         rh_status_q || exit 0
136         $1
137         ;;
138     restart)
139         $1
140         ;;
141     reload)
142         rh_status_q || exit 7
143         $1
144         ;;
145     force-reload)
146         force_reload
147         ;;
148     status)
149         rh_status
150         ;;
151     condrestart|try-restart)
152         rh_status_q || exit 0
153         restart
154         ;;
155     *)
156         echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
157         exit 2
158 esac
159 exit $?