From 02a94143dbda9cd2413d972d21f28a0f4024c15c Mon Sep 17 00:00:00 2001 From: Marc Schoechlin Date: Sun, 4 Jan 2015 12:50:32 +0100 Subject: [PATCH] check status of running status This adds a better output for some tasks if the broker is not running. The user gets the information that the broker is currently not running. Users are confused if they see a java stacktrace on invoking commands - often they do not read error output in detail. This change respects that the script can also be used to contact remote brokers - if ACTIVEMQ_QUEUEMANAGERURL is defined you get the regular stacktrace, because the script cannot know about the state if a remote broker. In >98% of all cases this script controls local instances - we should help the common user! --- assembly/src/release/bin/activemq | 67 ++++++++++++++++++++++++------- 1 file changed, 53 insertions(+), 14 deletions(-) diff --git a/assembly/src/release/bin/activemq b/assembly/src/release/bin/activemq index ca556d1039..b4d2c879bc 100755 --- a/assembly/src/release/bin/activemq +++ b/assembly/src/release/bin/activemq @@ -515,6 +515,9 @@ invoke_stop(){ # Invoke a task on a running ActiveMQ instance # +# $1 : "checkforrunning", do not invoke the task if activemq is not +# active +# , invoke task always # @RET : 0 => successful # !0 => something went wrong # @@ -524,22 +527,31 @@ invoke_stop(){ # - $ACTIVEMQ_SUNJMX_START : options for JMX settings # - $ACTIVEMQ_SSL_OPTS : options for SSL encryption invoke_task(){ + + local CHECKRUNNING="$1" ACTIVEMQ_OPTS="$ACTIVEMQ_OPTS $ACTIVEMQ_SSL_OPTS" - # call task in java binary - if ( checkRunning );then - if [ "$1" = "browse" ] && [ -n "$ACTIVEMQ_QUEUEMANAGERURL" ];then - COMMANDLINE_ARGS="$1 $ACTIVEMQ_QUEUEMANAGERURL `echo $COMMANDLINE_ARGS|sed 's,^browse,,'`" - elif [ "$1" = "query" ] && [ -n "$ACTIVEMQ_QUEUEMANAGERURL" ];then - COMMANDLINE_ARGS="$1 $ACTIVEMQ_SUNJMX_CONTROL `echo $COMMANDLINE_ARGS|sed 's,^query,,'`" - else - COMMANDLINE_ARGS="$COMMANDLINE_ARGS $ACTIVEMQ_SUNJMX_CONTROL" - fi - invokeJar - exit $? - else - invokeJar - exit 1 + + if [ "$CHECKRUNNING" = "checkforrunning" ];then + if ( ! checkRunning );then + echo "Activemq is not running." + exit 1 + fi fi + + # call task in java binary + if [ "$1" = "browse" ] && [ -n "$ACTIVEMQ_QUEUEMANAGERURL" ];then + COMMANDLINE_ARGS="$ACTIVEMQ_QUEUEMANAGERURL `echo $COMMANDLINE_ARGS|sed 's,^browse,,'`" + elif [ "$1" = "query" ] && [ -n "$ACTIVEMQ_QUEUEMANAGERURL" ];then + COMMANDLINE_ARGS="$ACTIVEMQ_SUNJMX_CONTROL `echo $COMMANDLINE_ARGS|sed 's,^query,,'`" + else + COMMANDLINE_ARGS="$COMMANDLINE_ARGS $ACTIVEMQ_SUNJMX_CONTROL" + fi + invokeJar + RET="$?" + if [ "$RET" != "0" ];then + echo "ERROR: task failed" + fi + exit $RET } show_help() { @@ -593,6 +605,33 @@ case "$1" in ;; stop) invoke_stop + exit $? + ;; + decrypt|encrypt|create) + invoke_task checknotforrunning + exit $? + ;; + query|bstat|dstat|purge) + # Only check for a running broker if "--jmxurl" is part of the COMMANDLINE_ARGS + if (echo "$COMMANDLINE_ARGS"|grep -q -- "--jmxurl");then + invoke_task checknotforrunning + RET="$?" + else + invoke_task checkforrunning + RET="$?" + fi + exit $RET + ;; + browse) + # Only check for a running broker if "--amqurl" is part of the COMMANDLINE_ARGS + if (echo "$COMMANDLINE_ARGS"|grep -q -- "--amqurl");then + invoke_task checknotforrunning + RET="$?" + else + invoke_task checkforrunning + RET="$?" + fi + exit $RET ;; *) invoke_task checkforrunning