You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucene.apache.org by "Shawn Heisey (JIRA)" <ji...@apache.org> on 2017/12/14 23:15:00 UTC

[jira] [Comment Edited] (SOLR-9168) Add availability to specify own oom handing script

    [ https://issues.apache.org/jira/browse/SOLR-9168?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16291765#comment-16291765 ] 

Shawn Heisey edited comment on SOLR-9168 at 12/14/17 11:14 PM:
---------------------------------------------------------------

I think it can just be done as an environment variable, optionally set in the include script (normally solr.in.sh).

SOLR_USER_OOM_EXE would be one idea for the variable name.  Feel free to bikeshed. ;)

Here's a patch against master with one idea.  I have not tested this.  The bin/solr script might need to explicitly export the environment variable.

If this code works, it will propagate the arguments supplied to oom_solr to the user-defined program.  There are a few other little tweaks in this patch.

{noformat}
diff --git a/solr/bin/oom_solr.sh b/solr/bin/oom_solr.sh
index 5ecba6b..a8c343f 100755
--- a/solr/bin/oom_solr.sh
+++ b/solr/bin/oom_solr.sh
@@ -17,14 +17,32 @@
 
 SOLR_PORT=$1
 SOLR_LOGS_DIR=$2
-SOLR_PID=`ps auxww | grep start.jar | grep $SOLR_PORT | grep -v grep | awk '{print $2}' | sort -r`
+SOLR_PID=`ps auxww | grep start\.jar | grep -w $SOLR_PORT | grep -v grep | awk '{print $2}' | sort -r`
 if [ -z "$SOLR_PID" ]; then
   echo "Couldn't find Solr process running on port $SOLR_PORT!"
-  exit
+  exit 1
 fi
 NOW=$(date +"%F_%H_%M_%S")
+OOM_LOG_FILE="$SOLR_LOGS_DIR/solr_oom_killer-$SOLR_PORT-$NOW.log"
 (
 echo "Running OOM killer script for process $SOLR_PID for Solr on port $SOLR_PORT"
 kill -9 $SOLR_PID
-echo "Killed process $SOLR_PID"
-) | tee $SOLR_LOGS_DIR/solr_oom_killer-$SOLR_PORT-$NOW.log
+echo "Killed process $SOLR_PID at $NOW"
+) | tee $OOM_LOG_FILE
+
+if [ -n "$SOLR_USER_OOM_EXE" ]; then
+  if [ -f "$SOLR_USER_OOM_EXE" ]; then
+    if [ -x "$SOLR_USER_OOM_EXE" ]; then
+      "$SOLR_USER_OOM_EXE" "$@" | tee -a $OOM_LOG_FILE
+      exit $?
+    else
+      echo User-defined OOM program $SOLR_USER_OOM_EXE found but not executable! \
+        | tee -a $OOM_LOG_FILE
+      exit 1
+    fi
+  else
+    echo User-defined OOM program $SOLR_USER_OOM_EXE not found! \
+        | tee -a $OOM_LOG_FILE
+    exit 1
+  fi
+fi
{noformat}



was (Author: elyograg):
I think it can just be done as an environment variable, optionally set in the include script (normally solr.in.sh).

SOLR_USER_OOM_EXE would be one idea for the variable name.  Feel free to bikeshed. ;)

Here's a patch against master with one idea.  I have not tested this.  The bin/solr script might need to explicitly export the environment variable.

If this code works, it will propagate the arguments supplied to oom_solr to the user-defined program.  There are a few other little tweaks in this patch.

{noformat}
diff --git a/solr/bin/oom_solr.sh b/solr/bin/oom_solr.sh
index 5ecba6b..c50b643 100755
--- a/solr/bin/oom_solr.sh
+++ b/solr/bin/oom_solr.sh
@@ -17,14 +17,32 @@
 
 SOLR_PORT=$1
 SOLR_LOGS_DIR=$2
-SOLR_PID=`ps auxww | grep start.jar | grep $SOLR_PORT | grep -v grep | awk '{print $2}' | sort -r`
+SOLR_PID=`ps auxww | grep start\.jar | grep -w $SOLR_PORT | grep -v grep | awk '{print $2}' | sort -r`
 if [ -z "$SOLR_PID" ]; then
   echo "Couldn't find Solr process running on port $SOLR_PORT!"
-  exit
+  exit 1
 fi
 NOW=$(date +"%F_%H_%M_%S")
+OOM_LOG_FILE="$SOLR_LOGS_DIR/solr_oom_killer-$SOLR_PORT-$NOW.log"
 (
 echo "Running OOM killer script for process $SOLR_PID for Solr on port $SOLR_PORT"
 kill -9 $SOLR_PID
-echo "Killed process $SOLR_PID"
-) | tee $SOLR_LOGS_DIR/solr_oom_killer-$SOLR_PORT-$NOW.log
+echo "Killed process $SOLR_PID at $NOW"
+) | tee $OOM_LOG_FILE
+
+if [ -n "$SOLR_USER_OOM_EXE" ]; then
+  if [ -f "$SOLR_USER_OOM_EXE" ]; then
+    if [ -x "$SOLR_USER_OOM_EXE" ]; then
+      "$SOLR_USER_OOM_EXE" "$@" | tee -a $OOM_LOG_FILE
+	  exit $?
+    else
+      echo User-defined OOM program $SOLR_USER_OOM_EXE found but not executable! \
+	    | tee -a $OOM_LOG_FILE
+      exit 1
+    fi
+  else
+    echo User-defined OOM program $SOLR_USER_OOM_EXE not found! \
+	    | tee -a $OOM_LOG_FILE
+    exit 1
+  fi
+fi
{noformat}


> Add availability to specify own oom handing script
> --------------------------------------------------
>
>                 Key: SOLR-9168
>                 URL: https://issues.apache.org/jira/browse/SOLR-9168
>             Project: Solr
>          Issue Type: Improvement
>          Components: scripts and tools
>    Affects Versions: 5.5.1
>            Reporter: AngryDeveloper
>              Labels: oom
>             Fix For: 5.5.1
>
>         Attachments: 0001-SOLR-9168-Allow-users-to-specify-their-own-OnOutOfMe.patch, SOLR-9168.patch
>
>
> Right now the start script always uses $SOLR_TIP/bin/oom_solr.sh  to handle OutOfMemoryException. This script only kills instance of solr.
> We need to do some additional things (e.g sent mail about this exception)
> What do you think about adding possibility to set up own script?
> Proposition:
> {code}
> if [ -z "$SOLR_OOM_SCRIPT" ]; then
>   SOLR_OOM_SCRIPT=$SOLR_TIP/bin/oom_solr.sh 
> fi
> [...]
> nohup "$JAVA" "${SOLR_START_OPTS[@]}" $SOLR_ADDL_ARGS \
> 	"-XX:OnOutOfMemoryError=$SOLR_OOM_SCRIPT $SOLR_PORT $SOLR_LOGS_DIR" \
>         -jar start.jar "${SOLR_JETTY_CONFIG[@]}" \
> 	1>"$SOLR_LOGS_DIR/solr-$SOLR_PORT-console.log" 2>&1 & echo $! > "$SOLR_PID_DIR/solr-$SOLR_PORT.pid"
> {code}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org