Uploaded image for project: 'eZ Publish / Platform'
  1. eZ Publish / Platform
  2. EZP-23464

solr init script for RHEL, Amazon Linux and CENTOS: stop kills wrong Java process

    XMLWordPrintable

Details

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: Critical Critical
    • None
    • None
    • None

    Description

      The init script gets the PID of the solr via pidof java. This works only if there is only one Java process. With multiple Java processes, those might be killed instead.

      I replaced this by ps ax | grep '[/]usr/bin/java -jar start.jar' | grep -v nohup | awk '{ print $1 }' which is not perfect either, but does the job unless there are other java processes running a start.jar.

      Changes to the attached init script:

      • Replaced pidof by ps and grep.
      • Replaced 2&>1 by 2>&1 in various places (see EZP-23463).
      • Got rid of RETVAL=$? in do_start, as this is always zero, due to the process being started in the background. The PID is being checked instead now.
      • used quotes around variables like $NAME, just in case someone changes it to contain whitespace
      diff
      @@ -27,12 +27,12 @@
       
       for JAVA in "$JAVA_HOME/bin/java" "/usr/bin/java" "/usr/local/bin/java"
       do
      -	if [ -x $JAVA ]
      +	if [ -x "$JAVA" ]
               then
       		break
       	fi
       done
      -if [ ! -x $JAVA ]
      +if [ ! -x "$JAVA" ]
       then
       	echo "Unable to locate java. Please set JAVA_HOME environment variable."
       	exit
      @@ -42,38 +42,47 @@
       
       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 &
      -    RETVAL=$?
      +    cd "$SOLR_HOME"
      +    daemon --check "$NAME" --pidfile "/var/run/$NAME.pid" nohup $JAVA -jar start.jar > /dev/null 2>&1 &
      +    cd "$CURRENT_DIR"
           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
      -    return $RETVAL
      +    
      +    # Using pidof is not good, as there might be other java processes as well.
      +    # Replaced this by calling ps. Still, this is somewhat awkward.
      +    # 2014-10-10 alex.schuster@ez.no
      +    #pid=`pidof java`
      +    pid=`ps ax | grep '[/]usr/bin/java -jar start.jar' | grep -v nohup | awk '{ print $1 }'`
      +    if [ -z $pid ]
      +    then
      +        echo "Error starting $NAME\!"
      +        return 1
      +    fi
      +    echo $pid > "/var/run/$NAME.pid"
      +    touch "/var/lock/subsys/$NAME"
      +    return 0
       }
       
       d_stop() {
      -    killproc -p /var/run/solr.pid $NAME >> /dev/null 2&>1
      +    killproc -p /var/run/solr.pid "$NAME" >> /dev/null 2>&1
           RETVAL=$?
      -    [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$NAME
      +    [ $RETVAL -eq 0 ] && rm -f "/var/lock/subsys/$NAME"
           return $RETVAL
       }
       
       d_restart() {
      -    d_stop >> /dev/null 2&>1
      +    d_stop  > /dev/null 2>&1
           sleep 1
      -    d_start >> /dev/null 2&>1
      +    d_start > /dev/null 2>&1
       }
       
       d_reload() {
      -    killproc -p /var/run/solr.pid $NAME -HUP 2&>1
      +    killproc -p /var/run/solr.pid "$NAME" -HUP > /dev/null 2>&1
           RETVAL=$?
           return $RETVAL
       }
       
       d_status() {
      -    status -p /var/run/solr.pid $NAME >> /dev/null 2&>1
      +    status -p /var/run/solr.pid "$NAME" > /dev/null 2>&1
           return $?
       }
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            Alex.Schuster@ibexa.co Alex Schuster
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: