Repository: activemq Updated Branches: refs/heads/trunk 815e0ec5b -> 7100bf377
https://issues.apache.org/jira/browse/AMQ-5378 - shell script improvements Project: http://git-wip-us.apache.org/repos/asf/activemq/repo Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/7100bf37 Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/7100bf37 Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/7100bf37 Branch: refs/heads/trunk Commit: 7100bf377ae3e2e537a789fb4566dfc72c8f8261 Parents: 815e0ec Author: Dejan Bosanac <[email protected]> Authored: Tue Dec 23 13:16:28 2014 +0100 Committer: Dejan Bosanac <[email protected]> Committed: Tue Dec 23 13:16:47 2014 +0100 ---------------------------------------------------------------------- assembly/src/release/bin/activemq | 54 ++++++++++++++++------------------ 1 file changed, 26 insertions(+), 28 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/activemq/blob/7100bf37/assembly/src/release/bin/activemq ---------------------------------------------------------------------- diff --git a/assembly/src/release/bin/activemq b/assembly/src/release/bin/activemq index 505ff63..9d80a09 100755 --- a/assembly/src/release/bin/activemq +++ b/assembly/src/release/bin/activemq @@ -33,13 +33,6 @@ COMMANDLINE_ARGS="$@" EXEC_OPTION="" -# For using instances -if ( basename $0 | grep "activemq-instance-" > /dev/null);then - INST="`basename $0|sed 's/^activemq-instance-//;s/\.sh$//'`" - ACTIVEMQ_CONFIGS="/etc/default/activemq-instance-${INST} $HOME/.activemqrc-instance-${INST}" - echo "INFO: Using alternative activemq configuration files: $ACTIVEMQ_CONFIGS" -fi - # ------------------------------------------------------------------------ # HELPERS @@ -146,7 +139,14 @@ fi # LOAD CONFIGURATION # CONFIGURATION -ACTIVEMQ_CONFIGS="$ACTIVEMQ_HOME/bin/env /etc/default/activemq $HOME/.activemqrc" +# For using instances +if ( basename $0 | grep "activemq-instance-" > /dev/null);then + INST="`basename $0|sed 's/^activemq-instance-//;s/\.sh$//'`" + ACTIVEMQ_CONFIGS="/etc/default/activemq-instance-${INST} $HOME/.activemqrc-instance-${INST}" + echo "INFO: Using alternative activemq configuration files: $ACTIVEMQ_CONFIGS" +else + ACTIVEMQ_CONFIGS="/etc/default/activemq $HOME/.activemqrc $ACTIVEMQ_HOME/bin/env" +fi # load activemq configuration CONFIG_LOAD="no" @@ -160,21 +160,16 @@ for ACTIVEMQ_CONFIG in $ACTIVEMQ_CONFIGS;do echo "INFO: Loading '$ACTIVEMQ_CONFIG'" . $ACTIVEMQ_CONFIG CONFIG_LOAD="yes" + break fi fi done # inform user that default configuration is loaded, no suitable configfile found if [ "$CONFIG_LOAD" != "yes" ];then - if [ "$1" != "setup" ];then echo "INFO: Using default configuration"; - echo "(you can configure options in one of these file: $ACTIVEMQ_CONFIGS)" - echo - echo "INFO: Invoke the following command to create a configuration file" - CONFIGS=`echo $ACTIVEMQ_CONFIGS|sed 's/[ ][ ]*/ | /'` - echo "$0 setup [ $CONFIGS ]" + echo " Configurations are loaded in the following order: $ACTIVEMQ_CONFIGS" echo - fi fi # ------------------------------------------------------------------------ @@ -198,7 +193,7 @@ if [ "$OSTYPE" = "cygwin" ]; then ACTIVEMQ_HOME="`cygpath --unix "$ACTIVEMQ_HOME"`" [ -n "$JAVA_HOME" ] && JAVA_HOME="`cygpath --unix "$JAVA_HOME"`" - [ -n "$CLASSPATH" ] && + [ -n "$ACTIVEMQ_CLASSPATH" ] && ACTIVEMQ_CLASSPATH="`cygpath --path --unix "$ACTIVEMQ_CLASSPATH"`" fi @@ -290,7 +285,7 @@ invokeJar(){ DOIT_PREFIX="sh -c " DOIT_POSTFIX=";" elif [ "`id -u`" = "0" ];then - DOIT_PREFIX="su -c " + DOIT_PREFIX="su -s /bin/sh -c " DOIT_POSTFIX=" - $ACTIVEMQ_USER" echo "INFO: changing to user '$ACTIVEMQ_USER' to invoke java" fi @@ -309,7 +304,7 @@ invokeJar(){ echo \"INFO: pidfile created : '$PIDFILE' (pid '\$APID')\";exit \$RET" $DOIT_POSTFIX RET="$?" elif [ -n "$PIDFILE" ] && [ "$PIDFILE" = "stop" ];then - PID=`cat ${ACTIVEMQ_PIDFILE}` + PID="`cat ${ACTIVEMQ_PIDFILE}`" $EXEC_OPTION $DOIT_PREFIX "\"$JAVACMD\" $ACTIVEMQ_OPTS $ACTIVEMQ_DEBUG_OPTS \ -Dactivemq.classpath=\"${ACTIVEMQ_CLASSPATH}\" \ -Dactivemq.home=\"${ACTIVEMQ_HOME}\" \ @@ -319,7 +314,7 @@ invokeJar(){ $ACTIVEMQ_CYGWIN \ -jar \"${ACTIVEMQ_HOME}/bin/activemq.jar\" $COMMANDLINE_ARGS --pid $PID & RET=\"\$?\"; APID=\"\$!\"; - echo \$APID > $ACTIVEMQ_DATA/stop.pid; exit \$RET" $DOIT_POSTFIX + echo \$APID > "${PIDFILE}.stop"; exit \$RET" $DOIT_POSTFIX RET="$?" else $EXEC_OPTION $DOIT_PREFIX "\"$JAVACMD\" $ACTIVEMQ_OPTS $ACTIVEMQ_DEBUG_OPTS \ @@ -351,8 +346,8 @@ checkRunning(){ echo "ERROR: Pidfile '$ACTIVEMQ_PIDFILE' exists but contains no pid" return 2 fi - PID=`cat $ACTIVEMQ_PIDFILE` - RET=`ps -p $PID|grep java` + PID="`cat $ACTIVEMQ_PIDFILE`" + RET="`ps -p $PID|grep java`" if [ -n "$RET" ];then return 0; else @@ -364,7 +359,7 @@ checkRunning(){ } checkStopRunning(){ - PID=$ACTIVEMQ_DATA/stop.pid + PID="${PIDFILE}.stop" if [ -f "$PID" ]; then if [ -z "`cat $PID`" ];then echo "ERROR: Pidfile '$PID' exists but contains no pid" @@ -542,8 +537,7 @@ invoke_task(){ } show_help() { - invokeJar - RET="$?" + invokeJar|sed "s,Usage: Main,Usage: $0," cat << EOF Tasks provided by the sysv init script: restart - stop running instance (if there is one), start new instance @@ -551,13 +545,17 @@ Tasks provided by the sysv init script: status - check if activemq process is running Configuration of this script: - Default configuration of this scriptThe configuration of this script can be placed on /etc/default/activemq or $HOME/.activemqrc. +The configuration of this script is read from the following files: + $ACTIVEMQ_CONFIGS + This script searches for the files in the listed order and reads the first available file. + Modify $ACTIVEMQ_BASE/bin/env or create a copy of that file on a suitable location. + To use additional configurations for running multiple instances on the same operating system rename or symlink script to a name matching to activemq-instance-<INSTANCENAME>. This changes the configuration location to /etc/default/activemq-instance-<INSTANCENAME> and - \$HOME/.activemqrc-instance-<INSTANCENAME>. Configuration files in /etc have higher precedence. + \$HOME/.activemqrc-instance-<INSTANCENAME>. EOF - exit $RET + exit 1 } # ------------------------------------------------------------------------ @@ -570,7 +568,7 @@ fi case "$1" in status) - invoke_status + invoke_status ;; restart) if ( checkRunning );then
