diff --git a/bin/scripts/rhel/solr b/bin/scripts/rhel/solr index d1164648..7adcf6a2 100644 --- a/bin/scripts/rhel/solr +++ b/bin/scripts/rhel/solr @@ -4,9 +4,19 @@ # # Usage: # -# Set the correct SOLR_HOME value, and copy this file to /etc/init.d, then -# - either run chkconfig --add solr, or -# - symlink to /etc/init.d/solr to /etc/rc3./S70solr and /etc/rc5./k70solr +# 1. installation +# Copy this file to /etc/init.d, then +# - either run chkconfig --add solr, or +# - symlink to /etc/init.d/solr to /etc/rc3./S70solr and /etc/rc5./k70solr +# +# 2. configuration +# Set options in /etc/sysconfig/solr +# Variables which can be defined in /etc/sysconfig/solr: +# SOLR_HOME (mandatory) +# JAVA_HOME +# PIDFILE +# LOCKFILE +# OPTIONS (for the JVM command-line) # # Example: # cp solr /etc/init.d/solr @@ -15,31 +25,64 @@ # cd /etc/rc5.d && ln -s ../init.d/solr S70solr # cd /etc/rc3.d && ln -s ../init.d/solr K70solr # cd /etc/rc5.d && ln -s ../init.d/solr K70solr +# echo "SOLR_HOME=/var/www/ezpublish/extension/ezfind/java" > /etc/sysconfig/solr +# # +# @todo use the standard messages from the init scripts for all operations instead of taking over with our version? +# +# @see http://fedoraproject.org/wiki/Packaging:SysVInitScript for return codes and general guidelines # # chkconfig: 2345 64 36 # description: SOLR indexing server # processname: solr # pidfile: /var/run/solr.pid +# config: /etc/sysconfig/solr + +source /etc/rc.d/init.d/functions DESC="Solr indexing server" NAME=solr -SOLR_HOME= # Set solr home here (example: /var/www/ezpublish/extension/ezfind/java) -JAVA_HOME= # Set java home here if java is not available in /usr/bin/java or /usr/local/bin/java +SOLR_HOME= # Set solr home here if you can not create /etc/sysconfig/solr (example: /var/www/ezpublish/extension/ezfind/java) +JAVA_HOME= # Set java home here if java is not available in /usr/bin/java or /usr/local/bin/java and you can not create /etc/sysconfig/solr +OPTIONS= -source /etc/rc.d/init.d/functions +if [ -f /etc/sysconfig/solr ]; then + . /etc/sysconfig/solr +fi +# @todo (maybe) allow var names from http://gitorious.org/opensuse/webpin2/blobs/master/solr.init as well +pidfile=${PIDFILE-/var/run/solr.pid} +lockfile=${LOCKFILE-/var/lock/subsys/solr} + +# check for java for JAVA in "$JAVA_HOME/bin/java" "/usr/bin/java" "/usr/local/bin/java" do - if [ -x $JAVA ] - then - break - fi + if [ -x $JAVA ]; then + break + fi done -if [ ! -x $JAVA ] -then - echo "Unable to locate java. Please set JAVA_HOME environment variable." - exit +if [ ! -x $JAVA ]; then + echo "Unable to locate java. Please set JAVA_HOME environment variable." + exit 6 +fi + +# check for solr +if [ ! -d "$SOLR_HOME" ]; then + echo "the directory $SOLR_HOME (SOLR_HOME) does not exist"; + if [ "$1" = "stop" ]; then + exit 0 + else + exit 5 + fi; +fi +SOLR_JAR="$SOLR_HOME/start.jar" +if [ ! -f "$SOLR_JAR" ]; then + echo "$SOLR_JAR not installed"; + if [ "$1" = "stop" ]; then + exit 0 + else + exit 5 + fi fi RETVAL=0 @@ -47,45 +90,47 @@ RETVAL=0 d_start() { CURRENT_DIR=`pwd` cd $SOLR_HOME - daemon --check $NAME --pidfile /var/run/solr.pid nohup $JAVA -jar start.jar > /dev/null 2>&1 & + daemon --check $NAME --pidfile ${pidfile} nohup $JAVA $OPTIONS -jar start.jar > /dev/null 2> /dev/null & RETVAL=$? - sleep 1 # Sleep 1 second, to make sure java is registered. - pid=`pidof java` - echo $pid > /var/run/solr.pid cd $CURRENT_DIR - [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$NAME + if [ $RETVAL -eq 0 ]; then + sleep 1 # Sleep 1 second, to make sure java is registered. + # @bug this is plain wrong, we might get many different java processes here... + pid=`pidof java` + echo $pid > ${pidfile} + touch ${lockfile} + fi return $RETVAL } d_stop() { - killproc -p /var/run/solr.pid $NAME >> /dev/null 2&>1 + # d_stop returns 0 even when process has been killed by hand. This might be confusing, so we let its std err/out get through + killproc -p ${pidfile} $NAME RETVAL=$? - [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$NAME + [ $RETVAL -eq 0 ] && rm -f ${lockfile} ${pidfile} return $RETVAL } d_restart() { - d_stop >> /dev/null 2&>1 + d_stop >> /dev/null sleep 1 - d_start >> /dev/null 2&>1 + d_start >> /dev/null } d_reload() { - killproc -p /var/run/solr.pid $NAME -HUP 2&>1 - RETVAL=$? - return $RETVAL + killproc -p ${pidfile} $NAME -HUP 2> /dev/null + return $? } d_status() { - status -p /var/run/solr.pid $NAME >> /dev/null 2&>1 + status -p ${pidfile} $NAME >> /dev/null 2> /dev/null return $? } case "$1" in start) echo " * Starting $DESC ($NAME)" - d_status - if [ $? -eq 0 ] + if d_status then echo " ...already running." else @@ -110,12 +155,8 @@ case "$1" in ;; restart) echo " * Restarting $DESC ($NAME)" - d_status - if [ $? -ne 0 ] + if d_status then - echo " ...not running." - RETVAL=1 - else if d_restart then echo " * ...done." @@ -123,6 +164,9 @@ case "$1" in echo " * ...failed." RETVAL=1 fi + else + echo " ...not running." + RETVAL=1 fi ;; reload) @@ -131,8 +175,7 @@ case "$1" in echo " ...done." ;; status) - d_status - if [ $? -eq 0 ] + if d_status then echo " * $DESC ($NAME) is running" else