1、在root权限下操作
2、cp /usr/local/activemq/bin/activemq /etc/init.d
3、cd /etc/init.d/
4、vi activemq
5、在第二行添加
#### BEGIN INIT INFO
# Provides: activemq
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 6
# chkconfig: 2345 64 36
# Short-Description: ActiveMQ server
### END INIT INFO
6、在最后一个#后添加
export JAVA_HOME=/usr/local/jdk7
ACTIVEMQ_HOME=/usr/local/activemq
7、chmod +x activemq
8、chkconfig --add activemq
9、chkconfig --list 显示该服务则成功
---------------------------------------------------------------------------------------------
在Ubuntu中,有可能没有chkconfig命令或者执行失败,可以用Ubuntu的update-rc.d命令替换
问题
cp 到/etc/init.d目录下的时候,有时候启动会提示找不到路径等等问题,但是在安装目录启动就可以,所以可以通过软连接来实现启动脚本:
ln -s /usr/local/activemq/bin/activemq /etc/init.d/
vi /etc/init.d/activemq
---------------------------------------------
# 第二行插入
# chkconfig: 345 63 37
# description: Auto start ActiveMQ
---------------------------------------------
然后就可以添加开机启动了
chkconfig activemq on
chkconfig --list activemq
也可以正常用服务的命令启动和停止
service activemq start
service activemq status
service activemq stop