Commits

Tavis Aitken committed 184b6a3

Updated the init.d script to properly start and stop elasticsearch

Comments (0)

Files changed (2)

elasticsearch/elasticsearch.init

-#! /bin/sh
+#! /bin/bash
 ### BEGIN INIT INFO
 # Provides:          elasticsearch
 # Required-Start:    $all
 # Default-Start:     2 3 4 5
 # Default-Stop:      0 1 6
 # Short-Description: Starts elasticsearch
-# Description:       Starts elasticsearch using start-stop-daemon
+# Description:        
 ### END INIT INFO
 
 # Source function library.
 . /etc/rc.d/init.d/functions
 
-ES_HOME=/var/lib/elasticsearch
-
-# Sourced from elasticsearch.in.sh
-
-CLASSPATH=$CLASSPATH:$ES_HOME/lib/*:$ES_HOME/lib/sigar/*
-
-if [ "x$ES_MIN_MEM" = "x" ]; then
-    ES_MIN_MEM=256m
-fi
-if [ "x$ES_MAX_MEM" = "x" ]; then
-    ES_MAX_MEM=1g
-fi
-
-# min and max heap sizes should be set to the same value to avoid
-# stop-the-world GC pauses during resize, and so that we can lock the
-# heap in memory on startup to prevent any of it from being swapped
-# out.
-JAVA_OPTS="$JAVA_OPTS -Xms${ES_MIN_MEM}"
-JAVA_OPTS="$JAVA_OPTS -Xmx${ES_MAX_MEM}"
-
-# reduce the per-thread stack size
-JAVA_OPTS="$JAVA_OPTS -Xss128k"
-
-JAVA_OPTS="$JAVA_OPTS -Djline.enabled=true"
-
-# Enable aggressive optimizations in the JVM
-JAVA_OPTS="$JAVA_OPTS -XX:+AggressiveOpts"
-
-# Enable reference compression, reducing memory overhead on 64bit JVMs
-#    - Disabled by default as it is not stable for Sun JVM before 6u19
-#JAVA_OPTS="$JAVA_OPTS -XX:+UseCompressedOops"
-
-JAVA_OPTS="$JAVA_OPTS -XX:+UseParNewGC"
-JAVA_OPTS="$JAVA_OPTS -XX:+UseConcMarkSweepGC"
-JAVA_OPTS="$JAVA_OPTS -XX:+CMSParallelRemarkEnabled"
-JAVA_OPTS="$JAVA_OPTS -XX:SurvivorRatio=8"
-JAVA_OPTS="$JAVA_OPTS -XX:MaxTenuringThreshold=1"
-JAVA_OPTS="$JAVA_OPTS -XX:CMSInitiatingOccupancyFraction=75"
-JAVA_OPTS="$JAVA_OPTS -XX:+UseCMSInitiatingOccupancyOnly"
-
-# Causes the JVM to dump its heap on OutOfMemory.
-JAVA_OPTS="$JAVA_OPTS -XX:+HeapDumpOnOutOfMemoryError"
-# The path to the heap dump location, note directory must exists and have enough
-# space for a full heap dump.
-#JAVA_OPTS="$JAVA_OPTS -XX:HeapDumpPath=$ES_HOME/logs/heapdump.hprof"
-
-
+ES_HOME=/usr/share/java/elasticsearch
 ES_USER=elasticsearch
+ES_INCLUDE=$ES_HOME/bin/elasticsearch.in.sh
 
 DAEMON=$ES_HOME/bin/elasticsearch
 NAME=elasticsearch
-DESC=elasticsearch
-PID_FILE=/var/run/$NAME.pid
+PID_FILE=${PIDFILE-/var/run/$NAME/$NAME.pid}
+LOCK_FILE=${LOCKFILE-/var/lock/subsys/$NAME}
 LOG_DIR=/var/log/$NAME
-DATA_DIR=/var/lib/$NAME
+DATA_DIR=$ES_HOME/data
 WORK_DIR=/tmp/$NAME
 CONFIG_FILE=/etc/$NAME/elasticsearch.yml
-DAEMON_OPTS="-p $PID_FILE -Des.config=$CONFIG_FILE -Des.path.home=$ES_HOME -Des.path.logs=$LOG_DIR -Des.path.data=$DATA_DIR -Des.path.work=$WORK_DIR"
+CONFIG_DIR=/etc/$NAME
+DAEMON_OPTS="-p $PID_FILE -Des.path.conf=$CONFIG_DIR -Des.config=$CONFIG_FILE -Des.path.home=$ES_HOME -Des.path.logs=$LOG_DIR -Des.path.data=$DATA_DIR -Des.path.work=$WORK_DIR"
 
+start() {
+    echo -n $"Starting $NAME: "
+    mkdir -p $WORK_DIR
+    daemon --pidfile=${PID_FILE} --user $ES_USER $DAEMON $DAEMON_OPTS   
+    RETVAL=$?
+    echo
+    [ $RETVAL -eq 0 ] && touch $LOCK_FILE
+    return $RETVAL
+}
 
-test -x $DAEMON || exit 0
-
-set -e
+stop() {
+	echo -n $"Stopping $NAME: "
+	killproc -p ${PID_FILE} -d 10 $DAEMON
+	RETVAL=$?
+	echo
+	[ $RETVAL = 0 ] && rm -f ${LOCK_FILE} ${PID_FILE}
+    return $RETVAL
+}
 
 case "$1" in
   start)
-    echo -n "Starting $DESC: "
-    mkdir -p $LOG_DIR $DATA_DIR $WORK_DIR
-    if daemon $DAEMON $DAEMON_OPTS -p $PID_FILE  
-    then
-        echo "started."
-    else
-        echo "failed."
-    fi
+    start
     ;;
   stop)
-    echo -n "Stopping $DESC: "
-    if start-stop-daemon --stop --pidfile $PID_FILE
-    then
-        echo "stopped."
-    else
-        echo "failed."
-    fi
+    stop 
+    ;;
+  status)
+        status -p ${PID_FILE} $DAEMON
+	RETVAL=$?
     ;;
   restart|force-reload)
-    ${0} stop
-    sleep 0.5
-    ${0} start
+    stop
+    start
     ;;
   *)
     N=/etc/init.d/$NAME
     echo "Usage: $N {start|stop|restart|force-reload}" >&2
-    exit 1
+    RETVAL=2
     ;;
 esac
 
-exit 0
+exit $RETVAL

elasticsearch/elasticsearch.spec

 %{__install} -p -m 644 lib/sigar/* %{buildroot}%{_javadir}/%{name}/lib/sigar
 
 # config
-%{__mkdir} -p %{buildroot}%{_javadir}/%{name}/config
-%{__install} -m 644 config/* %{buildroot}%{_javadir}/%{name}/config
+%{__mkdir} -p %{buildroot}%{_sysconfdir}/elasticsearch 
+%{__install} -m 644 config/* %{buildroot}%{_sysconfdir}/%{name}
 
 # data
 %{__mkdir} -p %{buildroot}%{_javadir}/%{name}/data
 
 # logs
-%{__mkdir} -p %{buildroot}%{_javadir}/%{name}/logs
+%{__mkdir} -p %{buildroot}%{_localstatedir}/log/%{name}
 
-# data
+# plugins 
 %{__mkdir} -p %{buildroot}%{_javadir}/%{name}/plugins
 
 # sysconfig and init
 %{__mkdir} -p %{buildroot}%{_sysconfdir}/{init.d,sysconfig}
 %{__install} -m 755 %{SOURCE1} %{buildroot}%{_sysconfdir}/init.d/elasticsearch
 
+%{__mkdir} -p %{buildroot}%{_localstatedir}/run/elasticsearch
+%{__mkdir} -p %{buildroot}%{_localstatedir}/lock/subsys/elasticsearch
+
 %pre
 # create elasticsearch group
 if ! getent group elasticsearch >/dev/null; then
 fi
 
 %post
-ln -s %{_javadir}/%{name}/config %{_sysconfdir}/elasticsearch
-ln -s %{_javadir}/%{name}/logs %{_localstatedir}/log/%{name}
 /sbin/chkconfig --add elasticsearch
 
 %preun
   /sbin/service elasticsearch stop >/dev/null 2>&1
   /sbin/chkconfig --del elasticsearch
 fi
-unlink %{_sysconfdir}/elasticsearch >/dev/null 2>&1
-unlink %{_localstatedir}/log/%{name} >/dev/null 2>&1
 
 %clean
 rm -rf $RPM_BUILD_ROOT
 %files
 %defattr(-,elasticsearch,elasticsearch,-)
 %{_sysconfdir}/init.d/elasticsearch
+%{_sysconfdir}/elasticsearch
+%{_localstatedir}/run/elasticsearch
 %dir %{_javadir}/elasticsearch
+%dir %{_localstatedir}/log/elasticsearch
 %{_javadir}/elasticsearch/*
 %doc LICENSE.txt  NOTICE.txt  README.textile