将此脚本放到/etc/init.d/ 并赋予可执行权限即可
注意 需要将java 及 mq安装目录改成你自己的
管理mqbroker
#/bin/bash
#author:firxiao
#date:20140917
#usage manage RocketMQ mqbroker
# chkconfig: - 99 90
pid=`ps ax | grep -i 'com.alibaba.rocketmq.broker.BrokerStartup' |grep java | grep -v grep | awk '{print $1}'`
##mq安装位置##
MQ_HOME=/opt/alibaba-rocketmq/bin
##java目录##
export JAVA_HOME=/opt/jdk
##log位置##
LOG_DIR=/var/log
function start()
{
if [ -n "$pid" ];
then
{
echo "The mqbroker(${pid}) is running..."
}
else
{
cd $MQ_HOME ; nohup sh mqbroker > $LOG_DIR/mqbroker.log 2>&1 &
echo $" mqbroker started logfile=$LOG_DIR/mqbroker.log"
}
fi
}
function stop()
{
if [ -z "$pid" ] ; then
echo "No mqbroker running."
exit -1;
fi
echo "The mqbroker(${pid}) is running..."
kill ${pid}
echo "Send shutdown request to mqbroker(${pid}) OK"
}
function status()
{
if [ -z "$pid" ] ; then
echo "No mqbroker running."
exit -1;
fi
echo "The mqbroker(${pid}) is running..."
}
case $1 in
start)
start
;;
stop)
stop
;;
status)
status
添加开机启动
#chkconfig --add /etc/init.d/mqbroker
#chkconfig mqbroker on
管理mqnamesrv
#/bin/bash
#author:firxiao
#data:20140917
#usage manage RocketMQ mqnamesrv
# chkconfig: - 80 81
pid=`ps ax | grep -i 'com.alibaba.rocketmq.namesrv.NamesrvStartup' |grep java | grep -v grep | awk '{print $1}'`
MQ_HOME=/opt/alibaba-rocketmq/bin
LOG_DIR=/var/log
function start()
{
if [ -n "$pid" ];
then
{
echo "The mqnamesrv(${pid}) is running..."
}
else
{
cd $MQ_HOME ; nohup sh mqnamesrv > $LOG_DIR/mqnamesrv.log 2>&1 &
echo $" mqnamesrv started logfile=$LOG_DIR/mqnamesrv.log"
}
fi
}
function stop()
{
if [ -z "$pid" ] ; then
echo "No mqnamesrv running."
exit -1;
fi
echo "The mqnamesrv(${pid}) is running..."
kill ${pid}
echo "Send shutdown request to mqnamesrv(${pid}) OK"
}
function status()
{
if [ -z "$pid" ] ; then
echo "No mqnamesrv running."
exit -1;
fi
echo "The mqnamesrv(${pid}) is running..."
}
case $1 in
start)
start
;;
stop)
stop
;;
status)
status
;;
*)
echo "Useage: $0 start|stop|status"
esac
添加开机启动
#chkconfig --add /etc/init.d/mqnamesrv
#chkconfig mqbroker on