CentOS环境activemq安装

http://activemq.apache.org/activemq-5140-release.html

tar -zxvf apache-activemq-5.14.0-bin.tar.gz
cd apache-activemq-5.14.0
cd bin
./activemq start

netstat -anp|grep 61616

web管理页面
http://IP:8161/admin

配置以service的方式启动

vi /etc/init.d/activemq
chmod +x activemq
chkconfig --add activemq
chkconfig activemq on

activemq文件

# chkconfig: 345 63 37
# description: Auto start ActiveMQ
JAVA_HOME=/usr/java/jdk1.8.0_60
JAVA_CMD=java
ACTIVEMQ_HOME=/data/activemq

#!/bin/sh

### BEGIN INIT INFO
# Provides:          activemq
# Required-Start:    $remote_fs $network $syslog
# Required-Stop:     $remote_fs $network $syslog
# Default-Start:     3 5
# Default-Stop:      0 1 6
# Short-Description: Starts ActiveMQ
# Description:       Starts ActiveMQ Message Broker Server
### END INIT INFO

# ------------------------------------------------------------------------
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ------------------------------------------------------------------------
#
# This script controls standalone Apache ActiveMQ service processes.
# To ensure compatibility to macosx and cygwin we do not utilize
# lsb standard infrastructure for controlling daemons like
# "start-stop-daemon".
#
# See also http://activemq.apache.org/activemq-command-line-tools-reference.html
# for additional commandline arguments
#
# System variables for this script, like ACTIVEMQ_OPTS and ACTIVEMQ_OPTS_MEMORY,
# can be configured in 'env' script located in this directory.
#
# For more information on configuring the script, see http://activemq.apache.org/unix-shell-script.html
#
#
# Authors:
# Marc Schoechlin <ms@256bit.org>

# ------------------------------------------------------------------------
# IMPROVED DEBUGGING (execute with bash -x)
# export PS4=' ${BASH_SOURCE}:${LINENO}(${FUNCNAME[0]}) '
#
# Backup invocation parameters
COMMANDLINE_ARGS="$@"
EXEC_OPTION=""

# ------------------------------------------------------------------------
# HELPERS

# a simple helper to get the current user
setCurrentUser(){
   CUSER="`whoami 2>/dev/null`"
   # Solaris hack
   if [ ! $? -eq 0 ]; then
      CUSER="`/usr/ucb/whoami 2>/dev/null`"
   fi
}

# get a canonical path, macosx and slowlaris does not support radlink -f :-)
pathCanonical() {
    local dst="${1}"
    while [ -h "${dst}" ] ; do
        ls=`ls -ld "${dst}"`
        link=`expr "$ls" : '.*-> \(.*\)$'`
        if expr "$link" : '/.*' > /dev/null; then
            dst="$link"
        else
            dst="`dirname "${dst}"`/$link"
        fi
    done
    local bas="`basename "${dst}"`"
    local dir="`dirname "${dst}"`"
    if [ "$bas" != "$dir" ]; then
      dst="`pathCanonical "$dir"`/$bas"
    fi
    echo "${dst}" | sed -e 's#//#/#g' -e 's#/\./#/#g' -e 's#/[^/]*/\.\./#/#g'
}


# a simple helper to get the activemq installation dir
getActiveMQHome(){
  # get the real path to the binary
  local REAL_BIN="`pathCanonical $0`"
  local REAL_DIR="`dirname $REAL_BIN`/../"
  REAL_DIR="`cd $REAL_DIR && pwd -P`"
  if [ -z "$REAL_DIR" ];then
      echo 'ERROR: unable to find real installtion path fo activemq, you have to define ACTIVEMQ_HOME manually in the config' >&2
      exit 1
  fi
  echo "$REAL_DIR/"

}

# Active MQ installation dir
if [ -z "$ACTIVEMQ_HOME" ] ; then
  ACTIVEMQ_HOME="`getActiveMQHome`"
fi

# Active MQ base dir
if [ -z "$ACTIVEMQ_BASE" ] ; then
  ACTIVEMQ_BASE="$ACTIVEMQ_HOME"
fi

# Configure user specified classpath here or externally using this variable
if [ -z "$ACTIVEMQ_USER_CLASSPATH" ] ; then
    ACTIVEMQ_USER_CLASSPATH=""
fi

# ActiveMQ Classpath configuration
ACTIVEMQ_CLASSPATH="$ACTIVEMQ_BASE/../lib/:$ACTIVEMQ_USER_CLASSPATH"

# Active MQ configuration directory
if [ -z "$ACTIVEMQ_CONF" ] ; then

    # For backwards compat with old variables we let ACTIVEMQ_CONFIG_DIR set ACTIVEMQ_CONF
    if [ -z "$ACTIVEMQ_CONFIG_DIR" ] ; then
        ACTIVEMQ_CONF="$ACTIVEMQ_BASE/conf"
    else
        ACTIVEMQ_CONF="$ACTIVEMQ_CONFIG_DIR"
    fi
fi

# Configure a user with non root privileges, if no user is specified do not change user
if [ -z "$ACTIVEMQ_USER" ] ; then
    ACTIVEMQ_USER=""
fi

# Active MQ data directory
if [ -z "$ACTIVEMQ_DATA" ] ; then

    # For backwards compat with old variables we let ACTIVEMQ_DATA_DIR set ACTIVEMQ_DATA
    if [ -z "$ACTIVEMQ_DATA_DIR" ] ; then
        ACTIVEMQ_DATA="$ACTIVEMQ_BASE/data"
    else
        ACTIVEMQ_DATA="$ACTIVEMQ_DATA_DIR"
    fi
fi

if [ -z "$ACTIVEMQ_TMP" ] ; then
  ACTIVEMQ_TMP="$ACTIVEMQ_BASE/tmp"
fi

if [ ! -d "$ACTIVEMQ_DATA" ]; then
   setCurrentUser
   if ( [ -z "$ACTIVEMQ_USER" ] || [ "$ACTIVEMQ_USER" = "$CUSER" ] );then
        mkdir $ACTIVEMQ_DATA
   elif [ "`id -u`" = "0" ];then
      su -c "mkdir $ACTIVEMQ_DATA" - $ACTIVEMQ_USER;
   fi
fi

# Location of the pidfile
if [ -z "$ACTIVEMQ_PIDFILE" ]; then
  ACTIVEMQ_PIDFILE="$ACTIVEMQ_DATA/activemq.pid"
fi


# ------------------------------------------------------------------------
# LOAD CONFIGURATION

# CONFIGURATION
# 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"
for ACTIVEMQ_CONFIG in $ACTIVEMQ_CONFIGS;do
   if [ -f "$ACTIVEMQ_CONFIG" ] ; then
     ( . $ACTIVEMQ_CONFIG >/dev/null 2>&1 )
     if [ "$?" != "0" ];then
      echo "ERROR: There are syntax errors in '$ACTIVEMQ_CONFIG'"
      exit 1
     else
       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
      echo "INFO: Using default configuration";
      echo "      Configurations are loaded in the following order: $ACTIVEMQ_CONFIGS"
      echo
fi

if [ -z "$ACTIVEMQ_OPTS" ] ; then
    ACTIVEMQ_OPTS="$ACTIVEMQ_OPTS_MEMORY -Djava.util.logging.config.file=logging.properties -Djava.security.auth.login.config=$ACTIVEMQ_CONF/login.config"
fi




# ------------------------------------------------------------------------
# OS SPECIFIC SUPPORT

OSTYPE="unknown"

case "`uname`" in
  CYGWIN*) OSTYPE="cygwin" ;;
  Darwin*)
           OSTYPE="darwin"
           if [ -z "$JAVA_HOME" ] && [ "$JAVACMD" = "auto" ];then
             JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Home
           fi
           ;;
esac

# For Cygwin, ensure paths are in UNIX format before anything is touched
if [ "$OSTYPE" = "cygwin" ]; then
  [ -n "$ACTIVEMQ_HOME" ] &&
    ACTIVEMQ_HOME="`cygpath --unix "$ACTIVEMQ_HOME"`"
  [ -n "$JAVA_HOME" ] &&
    JAVA_HOME="`cygpath --unix "$JAVA_HOME"`"
  [ -n "$ACTIVEMQ_CLASSPATH" ] &&
    ACTIVEMQ_CLASSPATH="`cygpath --path --unix "$ACTIVEMQ_CLASSPATH"`"
fi

# Detect the location of the java binary
if [ -z "$JAVACMD" ] || [ "$JAVACMD" = "auto" ] ; then
  if [ -n "$JAVA_HOME"  ] ; then
    if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
      # IBM's JDK on AIX uses strange locations for the executables
      JAVACMD="$JAVA_HOME/jre/sh/java"
    else
      JAVACMD="$JAVA_HOME/bin/java"
    fi
  fi
fi

# Hm, we still do not know the location of the java binary
if [ ! -x "$JAVACMD" ] ; then
    JAVACMD=`which java 2> /dev/null `
    if [ -z "$JAVACMD" ] ; then
        JAVACMD=java
    fi
fi
# Stop here if no java installation is defined/found
if [ ! -x "$JAVACMD" ] ; then
  echo "ERROR: Configuration variable JAVA_HOME or JAVACMD is not defined correctly."
  echo "       (JAVA_HOME='$JAVA_HOME', JAVACMD='$JAVACMD')"
  exit 1
fi

echo "INFO: Using java '$JAVACMD'"

if [ -z "$ACTIVEMQ_BASE" ] ; then
  ACTIVEMQ_BASE="$ACTIVEMQ_HOME"
fi

# For Cygwin, switch paths to Windows format before running java if [ "$OSTYPE" = "cygwin" ]; then
if [ "$OSTYPE" = "cygwin" ];then
  ACTIVEMQ_HOME="`cygpath --windows "$ACTIVEMQ_HOME"`"
  ACTIVEMQ_BASE="`cygpath --windows "$ACTIVEMQ_BASE"`"
  ACTIVEMQ_CONF="`cygpath --windows "$ACTIVEMQ_CONF"`"
  ACTIVEMQ_DATA="`cygpath --windows "$ACTIVEMQ_DATA"`"
  ACTIVEMQ_CLASSPATH=`cygpath --path --windows "$ACTIVEMQ_CLASSPATH"`
  [ -n "$JAVA_HOME" ] &&
    JAVA_HOME="`cygpath --windows "$JAVA_HOME"`"
  CYGHOME="`cygpath --windows "$HOME"`"
  ACTIVEMQ_TMP="`cygpath --windows "$ACTIVEMQ_TMP"`"
  if [ -n "$CYGHOME" ]; then
      ACTIVEMQ_CYGWIN="-Dcygwin.user.home=\"$CYGHOME\""
  fi
fi

# Set default classpath
# Add instance conf dir before AMQ install conf dir to pick up instance-specific classpath entries first
ACTIVEMQ_CLASSPATH="${ACTIVEMQ_CONF}:${ACTIVEMQ_CLASSPATH}"

if [ "$OSTYPE" = "cygwin" ];then
  # remove training backslashes to prevent quoting problems
  ACTIVEMQ_CLASSPATH="`echo ${ACTIVEMQ_CLASSPATH}|sed '~s,[\\]*$,,g'`"
  ACTIVEMQ_HOME="`echo ${ACTIVEMQ_HOME}|sed '~s,[\\]*$,,g'`"
  ACTIVEMQ_BASE="`echo ${ACTIVEMQ_BASE}|sed '~s,[\\]*$,,g'`"
  ACTIVEMQ_CONF="`echo ${ACTIVEMQ_CONF}|sed '~s,[\\]*$,,g'`"
  ACTIVEMQ_DATA="`echo ${ACTIVEMQ_DATA}|sed '~s,[\\]*$,,g'`"
fi

# Start the ActiveMQ JAR
#
#
# @ARG1 : the name of the PID-file
#         If specified, this function starts the java process in background as a daemon
#         and stores the pid of the created process in the file.
#         Output on stdout/stderr will be supressed if this parameter is specified
# @RET  : If unless 0 something went wrong
#
# Note: This function uses a lot of globally defined variables
# - if $ACTIVEMQ_USER is set, the function tries starts the java process whith the specified
#   user
invokeJar(){
   PIDFILE="$1"
   TASK_TODO="$2"
   RET="1"

   if [ ! -f "${ACTIVEMQ_HOME}/bin/activemq.jar" ];then
    echo "ERROR: '${ACTIVEMQ_HOME}/bin/activemq.jar' does not exist, define ACTIVEMQ_HOME in the config"
    exit 1
   fi

   setCurrentUser

   if ( [ -z "$ACTIVEMQ_USER" ] || [ "$ACTIVEMQ_USER" = "$CUSER" ] );then
      DOIT_PREFIX="sh -c "
      DOIT_POSTFIX=";"
   elif [ "`id -u`" = "0" ];then
      DOIT_PREFIX="su -s /bin/sh -c "
      DOIT_POSTFIX=" - $ACTIVEMQ_USER"
      echo "INFO: changing to user '$ACTIVEMQ_USER' to invoke java"
   fi
   # Execute java binary
   if [ -n "$TASK_TODO" ] && [ "$TASK_TODO" != "stop" ];then
      $EXEC_OPTION $DOIT_PREFIX "\"$JAVACMD\" $ACTIVEMQ_OPTS $ACTIVEMQ_DEBUG_OPTS \
              -Dactivemq.classpath=\"${ACTIVEMQ_CLASSPATH}\" \
              -Dactivemq.home=\"${ACTIVEMQ_HOME}\" \
              -Dactivemq.base=\"${ACTIVEMQ_BASE}\" \
              -Dactivemq.conf=\"${ACTIVEMQ_CONF}\" \
              -Dactivemq.data=\"${ACTIVEMQ_DATA}\" \
              $ACTIVEMQ_CYGWIN \
              -jar \"${ACTIVEMQ_HOME}/bin/activemq.jar\" $COMMANDLINE_ARGS >/dev/null 2>&1 &
              RET=\"\$?\"; APID=\"\$!\";
              echo \$APID > "${PIDFILE}";
              echo \"INFO: pidfile created : '${PIDFILE}' (pid '\$APID')\";exit \$RET" $DOIT_POSTFIX
      RET="$?"
   elif [ -n "$TASK_TODO" ] && [ "$TASK_TODO" = "stop" ];then
          SPID="`cat "${PIDFILE}"`"
          $EXEC_OPTION $DOIT_PREFIX "\"$JAVACMD\" $ACTIVEMQ_OPTS $ACTIVEMQ_DEBUG_OPTS \
              -Dactivemq.classpath=\"${ACTIVEMQ_CLASSPATH}\" \
              -Dactivemq.home=\"${ACTIVEMQ_HOME}\" \
              -Dactivemq.base=\"${ACTIVEMQ_BASE}\" \
              -Dactivemq.conf=\"${ACTIVEMQ_CONF}\" \
              -Dactivemq.data=\"${ACTIVEMQ_DATA}\" \
              $ACTIVEMQ_CYGWIN \
              -jar \"${ACTIVEMQ_HOME}/bin/activemq.jar\" $COMMANDLINE_ARGS --pid $SPID &
              RET=\"\$?\"; APID=\"\$!\";
              echo \$APID > "${PIDFILE}.stop"; exit \$RET" $DOIT_POSTFIX
      RET="$?"
   else
      $EXEC_OPTION $DOIT_PREFIX "\"$JAVACMD\" $ACTIVEMQ_OPTS $ACTIVEMQ_DEBUG_OPTS \
              -Dactivemq.classpath=\"${ACTIVEMQ_CLASSPATH}\" \
              -Dactivemq.home=\"${ACTIVEMQ_HOME}\" \
              -Dactivemq.base=\"${ACTIVEMQ_BASE}\" \
              -Dactivemq.conf=\"${ACTIVEMQ_CONF}\" \
              -Dactivemq.data=\"${ACTIVEMQ_DATA}\" \
              $ACTIVEMQ_CYGWIN \
              -jar \"${ACTIVEMQ_HOME}/bin/activemq.jar\" $COMMANDLINE_ARGS" $DOIT_POSTFIX
      RET="$?"
   fi
   return $RET
}

# Check if ActiveMQ 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
#
# 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
}

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"
        return 2
       fi
       THEPID=`cat ${PID_STOP}`
       RET=`ps -p $THEPID|grep java`
       if [ -n "$RET" ];then
         return 0;
       else
         return 1;
       fi
    else
         return 1;
    fi
}

# Check if ActiveMQ is running
#
# @RET  : 0 => the activemq process is running
#         1 => the activemq process is not running
#
# Note: This function uses globally defined variables
# - $ACTIVEMQ_PIDFILE : the name of the pid file


invoke_status(){
    if ( checkRunning );then
         PID="`cat $ACTIVEMQ_PIDFILE`"
         echo "ActiveMQ is running (pid '$PID')"
         exit 0
    fi
    echo "ActiveMQ not running"
    exit 1
}

# Start ActiveMQ if not already running
#
# @RET  : 0 => is now started, is already started
#         !0 => something went wrong
#
# Note: This function uses globally defined variables
# - $ACTIVEMQ_PIDFILE      : the name of the pid file
# - $ACTIVEMQ_OPTS         : Additional options
# - $ACTIVEMQ_SUNJMX_START : options for JMX settings
# - $ACTIVEMQ_SSL_OPTS     : options for SSL encryption

invoke_start(){
    if ( checkRunning );then
      PID="`cat $ACTIVEMQ_PIDFILE`"
      echo "INFO: Process with pid '$PID' is already running"
      exit 0
    fi

    ACTIVEMQ_OPTS="$ACTIVEMQ_OPTS $ACTIVEMQ_SUNJMX_START $ACTIVEMQ_SSL_OPTS -Djava.awt.headless=true -Djava.io.tmpdir=\"${ACTIVEMQ_TMP}\""

    echo "INFO: Starting - inspect logfiles specified in logging.properties and log4j.properties to get details"
    invokeJar "$ACTIVEMQ_PIDFILE" start
    exit "$?"
}

# Start ActiveMQ in foreground (for debugging)
#
# @RET  : 0 => was started
#         1 => was already started
#         !0 => somthing went wrong
#
# Note: This function uses globally defined variables
# - $ACTIVEMQ_PIDFILE      : the name of the pid file
# - $ACTIVEMQ_OPTS         : Additional options
# - $ACTIVEMQ_SUNJMX_START : options for JMX settings
# - $ACTIVEMQ_SSL_OPTS     : options for SSL encryption

invoke_console(){
    if ( checkRunning );then
      echo "ERROR: ActiveMQ is already running"
      exit 1
    fi

    ACTIVEMQ_OPTS="$ACTIVEMQ_OPTS $ACTIVEMQ_SUNJMX_START $ACTIVEMQ_SSL_OPTS -Djava.awt.headless=true -Djava.io.tmpdir=\"${ACTIVEMQ_TMP}\""

    COMMANDLINE_ARGS="start `echo $COMMANDLINE_ARGS|sed 's,^console,,'`"
    EXEC_OPTION="exec"
    echo "INFO: Starting in foreground, this is just for debugging purposes (stop process by pressing CTRL+C)"
    echo "INFO: Creating pidfile $ACTIVEMQ_PIDFILE"
    echo "$$" > "$ACTIVEMQ_PIDFILE"
    invokeJar "$ACTIVEMQ_PIDFILE"
    RET="$?"
    echo "INFO: removing pidfile $ACTIVEMQ_PIDFILE"
    exit "$RET"
}


# Kill ActiveMQ
# @RET    : 0 => stop was successful
#          !0 => something went wrong
#
# Note: This function uses globally defined variables
# - $ACTIVEMQ_PIDFILE         : the name of the pid file


invoke_kill(){
    if ( checkRunning ); then
       ACTIVEMQ_PID="`cat ${ACTIVEMQ_PIDFILE}`"
       echo "INFO: sending SIGKILL to pid '$ACTIVEMQ_PID'"
       kill -KILL $ACTIVEMQ_PID
       RET="$?"
       rm -f "${ACTIVEMQ_PIDFILE}"
       return $RET
    fi
    echo "INFO: not running, nothing to do"
    return 0
}


# Stop ActiveMQ
# @RET    : 0 => stop was successful
#          !0 => something went wrong
#
# Note: This function uses globally defined variables
# - $ACTIVEMQ_PIDFILE         : the name of the pid file
# - $ACTIVEMQ_KILL_MAXSECONDS : the number of seconds to wait for termination of broker after sending
#                              shutdown signal by jmx interface

invoke_stop(){
    RET="1"
    if ( checkRunning );then
       ACTIVEMQ_OPTS="$ACTIVEMQ_OPTS $ACTIVEMQ_SSL_OPTS"
       COMMANDLINE_ARGS="$COMMANDLINE_ARGS $ACTIVEMQ_SUNJMX_CONTROL"

       ACTIVEMQ_PID="`cat $ACTIVEMQ_PIDFILE`"

       invokeJar "$ACTIVEMQ_PIDFILE" "stop"
       RET="$?"

       FOUND="0"
       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
               echo " FINISHED"
               FOUND="1"
            fi
            break
         fi

         if (checkRunning);then
            sleep 1
            printf  "."
         else
            echo " TERMINATED"
            FOUND="1"
            break
         fi
         i="`expr $i + 1`"
       done
       if [ "$FOUND" -ne "1" ];then
         echo
         echo "INFO: Regular shutdown not successful,  sending SIGKILL to process"
         invoke_kill
         RET="$?"
       fi
    elif [ -f "$ACTIVEMQ_PIDFILE" ];then
       echo "ERROR: No or outdated process id in '$ACTIVEMQ_PIDFILE'"
       echo
       echo "INFO: Removing $ACTIVEMQ_PIDFILE"
    else
       echo "ActiveMQ not running"
       exit 0
    fi
    rm -f "$ACTIVEMQ_PIDFILE" >/dev/null 2>&1
    rm -f "$ACTIVEMQ_DATA/stop.pid" >/dev/null 2>&1
    exit $RET
}

# Invoke a task on a running ActiveMQ instance
#
# $1    : "checkforrunning", do not invoke the task if activemq is not
#         active
#         <other>, invoke task always
# @RET  : 0 => successful
#         !0 => something went wrong
#
# Note: This function uses globally defined variables
# - $ACTIVEMQ_QUEUEMANAGERURL : The url of the queuemanager
# - $ACTIVEMQ_OPTS            : Additional options
# - $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"

    if [ "$CHECKRUNNING" = "checkforrunning" ];then
       if ( ! checkRunning );then
         echo "Activemq is not running."
         exit 1
       fi
    elif [ "$CHECKRUNNING" = "checkfornotrunning" ];then
      if ( checkRunning );then
         echo "Activemq is 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 "$ACTIVEMQ_PIDFILE"
    RET="$?"
    exit $RET
}

show_help() {
  invokeJar "$ACTIVEMQ_PIDFILE"|sed "s,Usage: Main,Usage: $0,"
  cat << EOF
Tasks provided by the sysv init script:
    kill            - terminate instance in a drastic way by sending SIGKILL
    restart         - stop running instance (if there is one), start new instance
    console         - start broker in foreground, useful for debugging purposes
    status          - check if activemq process is running

Configuration of this script:
    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>.
EOF
  exit 1
}

# ------------------------------------------------------------------------
# MAIN

# show help
if [ -z "$1" ];then
 show_help
fi

case "$1" in
  status)
    invoke_status
    ;;
  restart)
    if ( checkRunning );then
      $0 stop
      echo
    fi
    $0 start
    $0 status
    ;;
  start)
    invoke_start
    ;;
  console)
    invoke_console
    exit $?
    ;;
  stop)
    invoke_stop
    exit $?
    ;;
  kill)
    invoke_kill
    exit $?
    ;;
  *)
    invoke_task
    exit $?
esac

也可以将activeMQ安装目录下的bin中的activemq文件拷贝到修改init.d/目录下,然后在文件开头添加一下内容

# chkconfig: 345 63 37
# description: Auto start ActiveMQ
JAVA_HOME=/usr/java/jdk1.8.0_60
JAVA_CMD=java
ACTIVEMQ_HOME=/data/activemq

#!/bin/sh

### BEGIN INIT INFO
# Provides:          activemq
# Required-Start:    $remote_fs $network $syslog
# Required-Stop:     $remote_fs $network $syslog
# Default-Start:     3 5
# Default-Stop:      0 1 6
# Short-Description: Starts ActiveMQ
# Description:       Starts ActiveMQ Message Broker Server
### END INIT INFO
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 204,684评论 6 478
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 87,143评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 151,214评论 0 337
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,788评论 1 277
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,796评论 5 368
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,665评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,027评论 3 399
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,679评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 41,346评论 1 299
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,664评论 2 321
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,766评论 1 331
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,412评论 4 321
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,015评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,974评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,203评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,073评论 2 350
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,501评论 2 343

推荐阅读更多精彩内容