This is an automated email from the ASF dual-hosted git repository. jbonofre pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/activemq.git
The following commit(s) were added to refs/heads/master by this push: new 18dce69 Remove duplicated code for finding a java process given a pidfile and make it work in busybox. new d065db7 Merge pull request #199 from fjollberg/master 18dce69 is described below commit 18dce69a78729e71841fead21c69dd15ffe7db58 Author: Fredrik Jönsson <f...@kth.se> AuthorDate: Fri Sep 23 10:09:54 2016 +0200 Remove duplicated code for finding a java process given a pidfile and make it work in busybox. --- assembly/src/release/bin/activemq | 61 +++++++++++++++------------------------ 1 file changed, 23 insertions(+), 38 deletions(-) diff --git a/assembly/src/release/bin/activemq b/assembly/src/release/bin/activemq index 1468aa9..b7c0c39 100755 --- a/assembly/src/release/bin/activemq +++ b/assembly/src/release/bin/activemq @@ -366,43 +366,27 @@ invokeJar(){ return $RET } -# Check if ActiveMQ is running +# Check if a java process (ActiveMQ) with pid found in file is running # -# @RET : 0 => the activemq process is running -# 1 => process id in $ACTIVEMQ_PIDFILE does not exist anymore -# 2 => something is wrong with the pid file +# @ARG1 : the name of the PID-file +# @RET : 0 => the java process is running +# 1 => process id in PID-file does not exist anymore +# 2 => something is wrong with the PID-file # # Note: This function uses globally defined variables # - $ACTIVEMQ_PIDFILE : the name of the pid file checkRunning(){ - if [ -f "$ACTIVEMQ_PIDFILE" ]; then - if [ -z "`cat $ACTIVEMQ_PIDFILE`" ];then - echo "ERROR: Pidfile '$ACTIVEMQ_PIDFILE' exists but contains no pid" - return 2 - fi - ACTIVEMQ_PID="`cat ${ACTIVEMQ_PIDFILE}`" - RET="`ps -p "${ACTIVEMQ_PID}"|grep java`" - if [ -n "$RET" ];then - return 0; - else - return 1; - fi - else - return 1; - fi -} + local pidfile="${1}" -checkStopRunning(){ - PID_STOP="${ACTIVEMQ_PIDFILE}.stop" - if [ -f "$PID_STOP" ]; then - if [ -z "`cat $PID_STOP`" ];then - echo "ERROR: Pidfile os stop process '$PID_STOP' exists but contains no pid" + if [ -f $pidfile ]; then + if [ -z "`cat "$pidfile"`" ];then + echo "ERROR: Pidfile '$pidfile' exists but contains no pid" return 2 fi - THEPID=`cat ${PID_STOP}` - RET=`ps -p $THEPID|grep java` + local activemq_pid="`cat "$pidfile"`" + local RET="`ps -o "pid,args" | grep "^$activemq_pid\s.*java"`" if [ -n "$RET" ];then return 0; else @@ -413,6 +397,7 @@ checkStopRunning(){ fi } + # Check if ActiveMQ is running # # @RET : 0 => the activemq process is running @@ -423,7 +408,7 @@ checkStopRunning(){ invoke_status(){ - if ( checkRunning );then + if ( checkRunning "$ACTIVEMQ_PIDFILE" );then PID="`cat $ACTIVEMQ_PIDFILE`" echo "ActiveMQ is running (pid '$PID')" exit 0 @@ -444,7 +429,7 @@ invoke_status(){ # - $ACTIVEMQ_SSL_OPTS : options for SSL encryption invoke_start(){ - if ( checkRunning );then + if ( checkRunning "$ACTIVEMQ_PIDFILE" );then PID="`cat $ACTIVEMQ_PIDFILE`" echo "INFO: Process with pid '$PID' is already running" exit 0 @@ -470,7 +455,7 @@ invoke_start(){ # - $ACTIVEMQ_SSL_OPTS : options for SSL encryption invoke_console(){ - if ( checkRunning );then + if ( checkRunning "$ACTIVEMQ_PIDFILE" );then echo "ERROR: ActiveMQ is already running" exit 1 fi @@ -498,7 +483,7 @@ invoke_console(){ invoke_kill(){ - if ( checkRunning ); then + if ( checkRunning "$ACTIVEMQ_PIDFILE" );then ACTIVEMQ_PID="`cat ${ACTIVEMQ_PIDFILE}`" echo "INFO: sending SIGKILL to pid '$ACTIVEMQ_PID'" kill -KILL $ACTIVEMQ_PID @@ -522,7 +507,7 @@ invoke_kill(){ invoke_stop(){ RET="1" - if ( checkRunning );then + if ( checkRunning "$ACTIVEMQ_PIDFILE" );then ACTIVEMQ_OPTS="$ACTIVEMQ_OPTS $ACTIVEMQ_SSL_OPTS" COMMANDLINE_ARGS="$COMMANDLINE_ARGS $ACTIVEMQ_SUNJMX_CONTROL" @@ -535,15 +520,15 @@ invoke_stop(){ i=0 echo "INFO: Waiting at least $ACTIVEMQ_KILL_MAXSECONDS seconds for regular process termination of pid '$ACTIVEMQ_PID' : " while [ "$i" -le "$ACTIVEMQ_KILL_MAXSECONDS" ]; do - if [ ! checkStopRunning ];then - if [ ! checkRunning ]; then + if ( ! checkRunning "${ACTIVEMQ_PIDFILE}.stop" ); then + if ( ! checkRunning "$ACTIVEMQ_PIDFILE" ); then echo " FINISHED" FOUND="1" fi break fi - if (checkRunning);then + if ( checkRunning "$ACTIVEMQ_PIDFILE" );then sleep 1 printf "." else @@ -591,12 +576,12 @@ invoke_task(){ ACTIVEMQ_OPTS="$ACTIVEMQ_OPTS $ACTIVEMQ_SSL_OPTS" if [ "$CHECKRUNNING" = "checkforrunning" ];then - if ( ! checkRunning );then + if ( ! checkRunning "$ACTIVEMQ_PIDFILE" );then echo "Activemq is not running." exit 1 fi elif [ "$CHECKRUNNING" = "checkfornotrunning" ];then - if ( checkRunning );then + if ( checkRunning "$ACTIVEMQ_PIDFILE" );then echo "Activemq is running." exit 1 fi @@ -650,7 +635,7 @@ case "$1" in invoke_status ;; restart) - if ( checkRunning );then + if ( checkRunning "$ACTIVEMQ_PIDFILE" );then $0 stop echo fi