linux系统服务的脚本文件都存放在/etc/init.d目录中,要把hornetq以系统服务方式运行,需要在/etc/init.d目录新建脚本hornetq
执行service hornetq start/stop/restart/status就可以对hornetq进行[启动/结束/重启/查看状态]操作。
注意:在RedHat中出现
原因是RedHat中默认的jdk为1.4.2,通过服务方式启动hornetq使用的是默认的jdk,而我们配置的JAVA_HOME=/usr/java/latest并没有起作用,因此需要在$HORNETQ_HOME/bin/run.sh中显式得使用/usr/java/latest/bin/java命令来代替java命令,更改后run.sh内容如下:
#!/bin/sh
JAVAHOME=/usr/java/latest
export HORNETQ_HOME=..
mkdir -p ../logs
# By default, the server is started in the non-clustered standalone configuration
if [ a"$1" = a ]; then CONFIG_DIR=$HORNETQ_HOME/config/stand-alone/non-clustered; else CONFIG_DIR="$1"; fi
if [ a"$2" = a ]; then FILENAME=hornetq-beans.xml; else FILENAME="$2"; fi
export CLASSPATH=$CONFIG_DIR:$HORNETQ_HOME/schemas/
#you can use the following line if you want to run with different ports
#export CLUSTER_PROPS="-Djnp.port=1099 -Djnp.rmiPort=1098 -Djnp.host=localhost -Dhornetq.remoting.netty.host=localhost -Dhornetq.remoting.netty.port=5445"
export JVM_ARGS="$CLUSTER_PROPS -XX:+UseParallelGC -XX:+AggressiveOpts -XX:+UseFastAccessorMethods -Xms512M -Xmx1024M -Dhornetq.config.dir=$CONFIG_DIR -Djava.util.logging.config.file=$CONFIG_DIR/logging.properties -Djava.library.path=."
#export JVM_ARGS="-Xmx512M -Djava.util.logging.config.file=$CONFIG_DIR/logging.properties -Dhornetq.config.dir=$CONFIG_DIR -Djava.library.path=. -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"
for i in `ls $HORNETQ_HOME/lib/*.jar`; do
CLASSPATH=$i:$CLASSPATH
done
echo "***********************************************************************************"
echo "java $JVM_ARGS -classpath $CLASSPATH org.hornetq.integration.bootstrap.HornetQBootstrapServer $FILENAME"
echo "***********************************************************************************"
$JAVAHOME/bin/java $JVM_ARGS -classpath $CLASSPATH -Dcom.sun.management.jmxremote org.hornetq.integration.bootstrap.HornetQBootstrapServer $FILENAME