I have not found information on the net for how to make ActiveMQ work as a daemon managed by the startup/init system for Gentoo, so I have had to create my own. Hopefully posting this information to this DL will enable others to find this information. I will also try to get this information posted elsewhere on the net, but feel free to use/post/re-use this information as you see fit.

------------------------------------------------------------------

In order to get ActiveMQ to run as a daemon and be managed by the init system on Gentoo, you will need to create two files. The first is the /etc/init.d/activemq which is the startup script as you would expect. The second is the /etc/conf.d/activemq configuration file, which (in case you are not familiar with Gentoo's startup system) is sourced by the init system when starting a script. Essentially, when Gentoo gets a request to start an init script, it checks in the /etc/conf.d directory for a file with the same name as the init script and if found, "sources" that file. As a result, the "Gentoo way" is to place most, if not all configuration into these "conf" files in the conf.d directory.

This script is relatively simple and meets my needs, enabling starting, stopping, and restarting (automagically handled by the init system, which recognizes that if you have a "start" and a "stop" that it can chain them together to get a restart). The system also seems to do a good job of managing the "pid" files and knowing when it has and has not been started. The commands and java config were taken from the activemq-admin script that is supplied with activemq. I have not tested the debug configuration and could probably be a little more cleaver than requiring one to uncomment/comment out the configuration, but perhaps someone will take this simple start and build upon it?

If you have any questions or comments on these, please feel free to respond back to the DL; however, please also copy me directly if you would like me to respond. Enjoy!

I left the Gentoo copyright statements (GNU flavor) as this was essentially re-used from their framework. I also borrowed heavily from the Gentoo startup scripts provided with the Tomcat project which demonstrated how to get the init system start and properly recognize java. As a result I take little credit for this work instead owing to the maintainers of the Gentoo Tomcat package for their ingenuity and hard work.

The files:

/etc/init.d/activemq
-------------------------------------------------------------------------
#!/sbin/runscript
# Copyright 1999-2004 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

depend() {
       use net
}

start() {
       ebegin "Starting ActiveMQ $1"
start-stop-daemon --start --background --make-pidfile --pidfile ${PIDFILE} --exec ${JAVA_HOME}/bin/java -- ${JAVA_OPTS} start >> ${OUTFILE} 2>&1
       eend $?
}

stop()  {
       ebegin "Stopping ActiveMQ $1"
start-stop-daemon --stop --pidfile ${PIDFILE} --exec ${JAVA_HOME}/bin/java -- ${JAVA_OPTS} stop
       eend $?
}
-------------------------------------------------------------------------

/etc/conf.d/activemq
-------------------------------------------------------------------------
JAVA_HOME=`java-config --jre-home`
ACTIVEMQ_HOME="/usr/share/activemq"
ACTIVEMQ_BASE="/usr/share/activemq"
ACTIVEMQ_CLASSPATH="${ACTIVEMQ_BASE}/conf;"$ACTIVEMQ_CLASSPATH
ACTIVEMQ_OPTS="-Xmx512M -Dorg.apache.activemq.UseDedicatedTaskRunner=true"
PIDFILE="/var/run/activemq.pid"
OUTFILE="/var/log/activemq.out"
# Uncomment to enable remote debugging
#ACTIVEMQ_DEBUG_OPTS="-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005"

JAVA_OPTS="$ACTIVEMQ_DEBUG_OPTS $ACTIVEMQ_OPTS -Dactivemq.classpath=${ACTIVEMQ_CLASSPATH} -Dactivemq.home=${ACTIVEMQ_HOME} -Dactivemq.base=${ACTIVEMQ_BASE} -jar ${ACTIVEMQ_HOME}/bin/run.jar"
--------------------------------------------------------------------------

Reply via email to