https://issues.apache.org/jira/browse/AMQ-3527 - ./activemq script cannot be started on Solaris OS 10. restrict to bourne syntax and add fallback for whoami

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1180032 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gary Tully 2011-10-07 13:21:45 +00:00
parent ab12a60a3a
commit 680bfee673
1 changed files with 52 additions and 42 deletions

View File

@ -36,7 +36,7 @@ COMMANDLINE_ARGS="$@"
# For using instances
if ( basename $0 | grep "activemq-instance-" > /dev/null);then
INST="$(basename $0|sed 's/^activemq-instance-//;s/\.sh$//')"
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: $ACCTIVEMQ_CONFIGS"
fi
@ -103,7 +103,7 @@ fi
# Location of the pidfile
if [ -z "$ACTIVEMQ_PIDFILE" ]; then
ACTIVEMQ_PIDFILE="$ACTIVEMQ_DATA_DIR/activemq-$(hostname).pid"
ACTIVEMQ_PIDFILE="$ACTIVEMQ_DATA_DIR/activemq-`hostname`.pid"
fi
# Location of the java installation
@ -237,8 +237,11 @@ if [ "$1" = "setup" ];then
fi
done < $0
) > $2
setCurrentUser
echo "INFO: It's recommend to limit access to '$2' to the priviledged user"
echo "INFO: (recommended: chown `whoami`:nogroup '$2'; chmod 600 '$2')"
echo "INFO: (recommended: chown '$CUSER':nogroup '$2'; chmod 600 '$2')"
exit $?
fi
@ -324,6 +327,16 @@ fi
# ------------------------------------------------------------------------
# HELPER FUNCTIONS
setCurrentUser(){
CUSER=`whoami 2>/dev/null`
# Solaris fix
if [ ! $? -eq 0 ]; then
CUSER=`/usr/ucb/whoami 2>/dev/null`
fi
}
# Start the ActiveMQ JAR
#
#
@ -339,22 +352,18 @@ fi
invokeJar(){
PIDFILE="$1"
RET="1"
CUSER="$(whoami 2>/dev/null)"
# Solaris fix
if [ ! $? -eq 0 ]; then
CUSER="$(/usr/ucb/whoami)"
fi
if [ ! -f "${ACTIVEMQ_HOME}/bin/run.jar" ];then
echo "ERROR: '${ACTIVEMQ_HOME}/bin/run.jar' does not exist"
exit 1
fi
setCurrentUser
if ( [ -z "$ACTIVEMQ_USER" ] || [ "$ACTIVEMQ_USER" = "$CUSER" ] );then
DOIT_PREFIX="sh -c "
DOIT_POSTFIX=";"
elif [ "$(id -u)" = "0" ];then
elif [ "`id -u`" = "0" ];then
DOIT_PREFIX="su -c "
DOIT_POSTFIX=" - $ACTIVEMQ_USER"
echo "INFO: changing to user '$ACTIVEMQ_USER' to invoke java"
@ -406,7 +415,7 @@ invokeJar(){
checkRunning(){
if [ -f "$ACTIVEMQ_PIDFILE" ]; then
if [ -z "$(cat $ACTIVEMQ_PIDFILE)" ];then
if [ -z "`cat $ACTIVEMQ_PIDFILE`" ];then
echo "ERROR: Pidfile '$ACTIVEMQ_PIDFILE' exists but contains no pid"
return 2
fi
@ -425,11 +434,12 @@ checkRunning(){
checkStopRunning(){
PID=$ACTIVEMQ_DATA_DIR/stop.pid
if [ -f "$PID" ]; then
if [ -z "$(cat $PID)" ];then
if [ -z "`cat $PID`" ];then
echo "ERROR: Pidfile '$PID' exists but contains no pid"
return 2
fi
RET=`ps -p $(cat $PID)|grep java`
THEPID=`cat $PID`
RET=`ps -p $THEPID|grep java`
if [ -n "$RET" ];then
return 0;
else
@ -503,7 +513,7 @@ invoke_console(){
ACTIVEMQ_OPTS="$ACTIVEMQ_OPTS $ACTIVEMQ_SUNJMX_START $ACTIVEMQ_SSL_OPTS"
COMMANDLINE_ARGS="start $(echo $COMMANDLINE_ARGS|sed 's,^console,,')"
COMMANDLINE_ARGS="start `echo $COMMANDLINE_ARGS|sed 's,^console,,'`"
echo "INFO: Starting in foreground, this is just for debugging purposes (stop process by pressing CTRL+C)"
invokeJar
exit "$?"
@ -584,10 +594,10 @@ invoke_task(){
if ( checkRunning );then
if [ "$1" = "browse" ] && [ -n "$ACTIVEMQ_QUEUEMANAGERURL" ];then
ACTIVEMQ_OPTS="$ACTIVEMQ_OPTS $ACTIVEMQ_SSL_OPTS"
COMMANDLINE_ARGS="$1 $ACTIVEMQ_QUEUEMANAGERURL $(echo $COMMANDLINE_ARGS|sed 's,^browse,,')"
COMMANDLINE_ARGS="$1 $ACTIVEMQ_QUEUEMANAGERURL `echo $COMMANDLINE_ARGS|sed 's,^browse,,'`"
elif [ "$1" = "query" ] && [ -n "$ACTIVEMQ_QUEUEMANAGERURL" ];then
ACTIVEMQ_OPTS="$ACTIVEMQ_OPTS $ACTIVEMQ_SSL_OPTS"
COMMANDLINE_ARGS="$1 $ACTIVEMQ_SUNJMX_CONTROL $(echo $COMMANDLINE_ARGS|sed 's,^query,,')"
COMMANDLINE_ARGS="$1 $ACTIVEMQ_SUNJMX_CONTROL `echo $COMMANDLINE_ARGS|sed 's,^query,,'`"
else
ACTIVEMQ_OPTS="$ACTIVEMQ_OPTS $ACTIVEMQ_SSL_OPTS"
COMMANDLINE_ARGS="$COMMANDLINE_ARGS $ACTIVEMQ_SUNJMX_CONTROL"