Hello,
> > could you not using such a 'sites-enabled' directory like apache2
> > for your ActiveMQ init script?
>
> That's sound a greate idea but I run out of time to implement this.
> Are you willing to provide patch ?
I have created an patch against your master branch in git. This patch
contains some modifications to work with instances-available and
instances-enabled.
Greets,
Jonas
diff --git a/debian/activemq-options b/debian/activemq-options
new file mode 100644
index 0000000..bc60801
--- /dev/null
+++ b/debian/activemq-options
@@ -0,0 +1,14 @@
+# Time to wait for the server to start, in seconds
+STARTTIME=5
+
+# !!! Use a specific data directory for each instance
+ACTIVEMQ_BASE="/var/lib/activemq/$INSTANCE"
+
+# Use openjdk-6 as default Java runtime
+JAVA_HOME="/usr/lib/jvm/java-6-openjdk/"
+
+# Set some JVM memory options
+ACTIVEMQ_OPTS="-Xms512M -Xmx512M -Dorg.apache.activemq.UseDedicatedTaskRunner=true"
+
+# Arguments to launch /usr/bin/activemq
+ACTIVEMQ_ARGS="start xbean:activemq.xml"
diff --git a/debian/activemq.README.Debian b/debian/activemq.README.Debian
index 6691171..c71d82a 100644
--- a/debian/activemq.README.Debian
+++ b/debian/activemq.README.Debian
@@ -17,10 +17,16 @@ on port 61616, with OpenWire protocol enabled.
Messages storage is handled by kahadb in /var/lib/activemq/main/data/kahadb
You can customize its environnement here :
- /etc/default/activemq
-
+ cp /usr/share/activemq/activemq-options /etc/activemq/instances-available/main/options
+
+Edit the file /etc/activemq/instances-available/main/options and restart it.
+
And it's XML configuration can be edited here :
- /etc/activemq/main.xml
+ /etc/activemq/instances-available/main/activemq.xml
+
+Enable it:
+ ln -s /etc/activemq/instances-available/main \
+ /etc/activemq/instances-enabled/main
Start it :
invoke-rc.d activemq start
@@ -29,19 +35,27 @@ Setup a new ActiveMQ instance
-----------------------------
To create a new instance, you have to :
- cp /etc/default/activemq /etc/default/activemq-<instancename>
+ mkdir /etc/activemq/instances-available/<instancename>
+
+Create your own configuration into
+ /etc/activemq/instances-available/<instancename>/activemq.xml
+
+For example, you can copy a sample configuration :
+ cp /etc/activemq/instances-available/main/* \
+ /etc/activemq/instances-available/<instancename>/
+
+If you need some other Xms / Xmx settings or want to use another JDK:
+
+ cp /usr/share/activemq/activemq-options \
+ /etc/activemq/instances-available/<instancename>/options
In this file, you can modify ACTIVEMQ_BASE if you want to store
your data elsewhere than /var/lib/activemq/<instancename>/ or
JAVA_HOME if you want to use another JDK.
-Create your own configuration into /etc/activemq/<instancename>.xml
-For example, you can copy a sample configuration :
- mkdir /etc/activemq/<instancename>/
- cp /etc/activemq/main/* /etc/activemq/<instancename>/
-
-Register this instance into sysvinit:
- ln -s /etc/init.d/activemq /etc/init.d/activemq-<instancename>
+Register this instance into enabled:
+ ln -s /etc/activemq/instances-available/<instancename> \
+ /etc/activemq/instances-enabled/<instancename>
Start it :
- invoke-rc.d activemq-[name] start
+ invoke-rc.d activemq start
diff --git a/debian/activemq.default b/debian/activemq.default
index 70bc85a..c06b810 100644
--- a/debian/activemq.default
+++ b/debian/activemq.default
@@ -1,35 +1,8 @@
-# ActiveMQ instance configuration
-# NB: It receive $INSTANCE variable from /etc/init.d/activemq script
-
# Whether to start ActiveMQ (as a daemon or not)
NO_START=0
-# Time to wait for the server to die, in seconds
-DIETIME=3
-
-# Time to wait for the server to start, in seconds
-STARTTIME=5
-
-# Global (readonly) shared activemq installation
-ACTIVEMQ_HOME=/usr/share/activemq
-
-# !!! Use a specific data directory for each instance
-ACTIVEMQ_BASE="/var/lib/activemq/$INSTANCE"
-
-# Default directory to find XML configuration files
-ACTIVEMQ_CONFIG_DIR="/etc/activemq/$INSTANCE"
-
-# !!! Use a specific PID file for each instance
-ACTIVEMQ_PIDFILE="/var/run/activemq/$INSTANCE.pid"
-
-# Use openjdk-6 as default Java runtime
-JAVA_HOME="/usr/lib/jvm/java-6-openjdk/"
-
# Use Debian create user to run ActiveMQ process
ACTIVEMQ_USER="activemq"
-# Set some JVM memory options
-ACTIVEMQ_OPTS="-Xms512M -Xmx512M -Dorg.apache.activemq.UseDedicatedTaskRunner=true"
-
-# Arguments to launch /usr/bin/activemq
-ACTIVEMQ_ARGS="start xbean:activemq.xml"
+# Time to wait for the server to die, in seconds
+DIETIME=2
diff --git a/debian/activemq.dirs b/debian/activemq.dirs
index 29b8187..990a76c 100644
--- a/debian/activemq.dirs
+++ b/debian/activemq.dirs
@@ -1,4 +1,6 @@
/etc/activemq
+/etc/activemq/instances-enabled
+/etc/activemq/instances-available
/usr/share/activemq
/usr/share/activemq/bin
@@ -6,4 +8,4 @@
/usr/share/activemq/lib/optional
/var/lib/activemq
-/var/lib/activemq/data
\ No newline at end of file
+/var/lib/activemq/data
diff --git a/debian/activemq.init b/debian/activemq.init
index 0841bcc..3d4a45b 100644
--- a/debian/activemq.init
+++ b/debian/activemq.init
@@ -10,25 +10,16 @@
### END INIT INFO
# Author: Damien Raude-Morvan <draz...@debian.org>
-
-# Check init script name to detect instance name
-INSTANCE="main"
-if ( basename $0 | grep "activemq-" > /dev/null);then
- INSTANCE="$(basename $0 | sed 's/^activemq-//;s/\.sh$//')"
-fi
-export INSTANCE
+# Author: Jonas Genannt <jonas.gena...@capi2name.de>
PATH=/sbin:/usr/sbin:/bin:/usr/bin
-DESC="ActiveMQ $INSTANCE instance"
+DESC="ActiveMQ instance"
NAME=activemq
DAEMON=/usr/bin/$NAME
SCRIPTNAME=/etc/init.d/`basename $0`
DEFAULT=/etc/default/$NAME
ACTIVEMQ_JAR=/usr/share/activemq/bin/run.jar
-if [ "$INSTANCE" != "main" ]; then
- DEFAULT=/etc/default/$NAME-$INSTANCE
- NAME=activemq-$INSTANCE
-fi
+ACTIVEMQ_INSTANCES_ENABLED=/etc/activemq/instances-enabled
# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh
@@ -38,50 +29,16 @@ fi
# and status_of_proc is working.
. /lib/lsb/init-functions
-# Default options, these can be overriden by the information
-# at /etc/default/activemq-$INSTANCE
-
# Whether to start ActiveMQ (as a daemon or not)
NO_START=0
-# Time to wait for the server to die, in seconds
-DIETIME=3
-
-# Time to wait for the server to start, in seconds
-STARTTIME=5
-
-# Global (readonly) shared activemq installation
-ACTIVEMQ_HOME=/usr/share/activemq
-
-# !!! Use a specific data directory for each instance
-ACTIVEMQ_BASE="/var/lib/activemq/$INSTANCE"
-
-# Default directory to find XML configuration files
-ACTIVEMQ_CONFIG_DIR="/etc/activemq/$INSTANCE"
+ACTIVEMQ_USER=activemq
-# !!! Use a specific PID file for each instance
-ACTIVEMQ_PIDFILE="/var/run/activemq/$INSTANCE.pid"
-
-# Use openjdk-6 as default Java runtime
-JAVA_HOME="/usr/lib/jvm/java-6-openjdk/"
-
-# Use Debian create user to run ActiveMQ process
-ACTIVEMQ_USER="activemq"
-
-# Set some JVM memory options
-ACTIVEMQ_OPTS="-Xms512M -Xmx512M -Dorg.apache.activemq.UseDedicatedTaskRunner=true"
-
-# Arguments to launch /usr/bin/activemq
-ACTIVEMQ_ARGS="start xbean:activemq.xml"
-
-# End of variables that can be overwritten
+DIETIME=2
# Read configuration variable file if it is present
[ -r $DEFAULT ] && . $DEFAULT
-# No need to exports variables, as /usr/bin/activemq will source
-# /etc/default/activemq-$INSTANCE
-
# Exit now if daemon binary is not installed
test -x $DAEMON || exit 0
@@ -104,6 +61,15 @@ if [ "$NO_START" != "0" -a "$1" != "stop" ]; then
exit 0
fi
+# Check if any instances exists in instances-enabled directory
+check_instances_enabled() {
+ if [ -d "$ACTIVEMQ_INSTANCES_ENABLED" ] && [ `/bin/ls $ACTIVEMQ_INSTANCES_ENABLED | wc -l` -gt 0 ]; then
+ return 1
+ else
+ return 0
+ fi
+}
+
# Check if a given process pid's cmdline matches a given name
running_pid() {
pid=$1
@@ -127,23 +93,72 @@ running() {
}
# Start the process using the wrapper
-start_server() {
+start_servers() {
mkdir -p /var/run/activemq/
chown $ACTIVEMQ_USER /var/run/activemq/
- start-stop-daemon --start --quiet --pidfile $ACTIVEMQ_PIDFILE \
- --chuid $ACTIVEMQ_USER --background \
- --name java --startas $DAEMON -- $ACTIVEMQ_ARGS
- errcode=$?
- return $errcode
+
+ if check_instances_enabled; then
+ echo "No instances found at ${ACTIVEMQ_INSTANCES_ENABLED}."
+ exit 0
+ fi
+
+ for INSTANCE in `ls $ACTIVEMQ_INSTANCES_ENABLED`; do
+ if [ -d "${ACTIVEMQ_INSTANCES_ENABLED}/${INSTANCE}" ]; then
+ ACTIVEMQ_PIDFILE="/var/run/activemq/$INSTANCE.pid"
+ ACTIVEMQ_CONFIG_DIR="$ACTIVEMQ_INSTANCES_ENABLED/$INSTANCE"
+
+ export INSTANCE
+ export ACTIVEMQ_USER
+ export ACTIVEMQ_PIDFILE
+ export ACTIVEMQ_HOME=/usr/share/activemq
+ export ACTIVEMQ_CONFIG_DIR
+
+ # Import global configuration
+ . /usr/share/activemq/activemq-options
+ # Import per instance configuration
+ [ -r "${ACTIVEMQ_CONFIG_DIR}/options" ] && . ${ACTIVEMQ_CONFIG_DIR}/options
+
+ log_progress_msg "$INSTANCE"
+
+ start-stop-daemon --start --quiet --pidfile $ACTIVEMQ_PIDFILE \
+ --chuid $ACTIVEMQ_USER --background \
+ --name java --startas $DAEMON -- $ACTIVEMQ_ARGS
+
+ errcode=$?
+ if [ ! $errcode ]; then
+ log_progress_msg "(failed)"
+ else
+ [ -n "$STARTTIME" ] && sleep $STARTTIME # Wait some time
+ if running; then
+ log_progress_msg "(running)"
+ else
+ log_progress_msg "(failed?)"
+ fi
+ fi
+ else
+ echo -n "${INSTANCE} (not an directory)"
+ fi
+ done
}
# Stop the process using the wrapper
-stop_server() {
- start-stop-daemon --stop --quiet --pidfile $ACTIVEMQ_PIDFILE \
- --user $ACTIVEMQ_USER \
- --name java --startas $DAEMON -- stop
- errcode=$?
- return $errcode
+stop_servers() {
+ for INSTANCE in `ls /var/run/activemq/`; do
+ INSTANCE=$(echo $INSTANCE | sed 's@.pid@@')
+ ACTIVEMQ_PIDFILE="/var/run/activemq/$INSTANCE.pid"
+ log_progress_msg "$INSTANCE"
+ start-stop-daemon --stop --quiet --pidfile $ACTIVEMQ_PIDFILE \
+ --user $ACTIVEMQ_USER \
+ --name java --startas $DAEMON -- stop
+ if running; then
+ force_stop
+ fi
+ if running; then
+ log_progress_msg "(failed)"
+ else
+ log_progress_msg "(stopped)"
+ fi
+ done
}
# Force the process to die killing it manually
@@ -169,70 +184,36 @@ force_stop() {
case "$1" in
start)
log_daemon_msg "Starting $DESC " "$NAME"
- # Check if it's running first
- if running ; then
- log_progress_msg "apparently already running"
- log_end_msg 0
- exit 0
- fi
- if start_server ; then
- # NOTE: Some servers might die some time after they start,
- # this code will detect this issue if STARTTIME is set
- # to a reasonable value
- [ -n "$STARTTIME" ] && sleep $STARTTIME # Wait some time
- if running ; then
- # It's ok, the server started and is running
- log_end_msg 0
- else
- # It is not running after we did start
- log_end_msg 1
- fi
- else
- # Either we could not start it
- log_end_msg 1
- fi
+ start_servers
+ log_end_msg 0
;;
stop)
log_daemon_msg "Stopping $DESC" "$NAME"
- if running ; then
- # Only stop the server if we see it running
- errcode=0
- stop_server || errcode=$?
- # Is it really dead?
- sleep "$DIETIME"s
- if running; then
- force_stop || errcode=$?
- fi
- log_end_msg $errcode
- else
- # If it's not running don't do anything
- log_progress_msg "apparently not running"
+ stop_servers
log_end_msg 0
- exit 0
- fi
;;
restart|force-reload)
log_daemon_msg "Restarting $DESC" "$NAME"
- errcode=0
- stop_server || errcode=$?
- # Wait some sensible amount, some server need this
- [ -n "$DIETIME" ] && sleep $DIETIME
- start_server || errcode=$?
- [ -n "$STARTTIME" ] && sleep $STARTTIME
- running || errcode=$?
- log_end_msg $errcode
+ stop_servers
+ start_servers
+ log_end_msg 0
;;
status)
-
log_daemon_msg "Checking status of $DESC" "$NAME"
- if running ; then
- log_progress_msg "running"
- log_end_msg 0
- else
- log_progress_msg "apparently not running"
- log_end_msg 1
- exit 1
- fi
+
+ for INSTANCE in `ls $ACTIVEMQ_INSTANCES_ENABLED`; do
+ if [ -d "${ACTIVEMQ_INSTANCES_ENABLED}/${INSTANCE}" ]; then
+ ACTIVEMQ_PIDFILE="/var/run/activemq/${INSTANCE}.pid"
+ log_progress_msg "$INSTANCE"
+ if running; then
+ log_progress_msg "(running)"
+ else
+ log_progress_msg "(stopped)"
+ fi
+ fi
+ done
+
+ log_end_msg 0
;;
reload)
log_warning_msg "Reloading $NAME daemon: not implemented, as the daemon"
@@ -244,4 +225,4 @@ case "$1" in
;;
esac
-exit 0
\ No newline at end of file
+exit 0
diff --git a/debian/activemq.install b/debian/activemq.install
index 6a3f0cc..89d2a47 100644
--- a/debian/activemq.install
+++ b/debian/activemq.install
@@ -15,5 +15,8 @@ assembly/src/release/bin/activemq-admin /usr/bin/
assembly/src/release/bin/activemq /usr/bin/
# Default configuration
-debian/activemq.xml /etc/activemq/main/
-assembly/src/release/conf/log4j.properties /etc/activemq/main/
\ No newline at end of file
+debian/activemq.xml /etc/activemq/instances-available/main/
+assembly/src/release/conf/log4j.properties /etc/activemq/instances-available/main/
+
+# Default env
+debian/activemq-options /usr/share/activemq/
diff --git a/debian/patches/init_debian_default_values.diff b/debian/patches/init_debian_default_values.diff
index 880018e..f656689 100644
--- a/debian/patches/init_debian_default_values.diff
+++ b/debian/patches/init_debian_default_values.diff
@@ -5,26 +5,41 @@ Description: Init script for ActiveMQ : Use default values compliant with
ACTIVEMQ_CONFIG_DIR="/etc/activemq"
ACTIVEMQ_PIDFILE="/var/run/activemq.pid"
JAVA_HOME="/usr/lib/jvm/java-6-openjdk/"
+ Create data directory and chown to $ACTIVEMQ_USER
Author: Damien Raude-Morvan <draz...@debian.org>
Last-Update: 2011-07-22
Forwarded: not-needed
+
+diff --git a/assembly/src/release/bin/activemq b/assembly/src/release/bin/activemq
+index c159d11..ccd67d2 100755
--- a/assembly/src/release/bin/activemq
+++ b/assembly/src/release/bin/activemq
-@@ -29,7 +29,12 @@
+@@ -29,18 +29,16 @@
# ------------------------------------------------------------------------
# CONFIGURATION
-ACTIVEMQ_CONFIGS="/etc/default/activemq $HOME/.activemqrc"
-+if ([ "x$INSTANCE" = "xmain" ] || [ -z "$INSTANCE" ]) ; then
-+ ACTIVEMQ_CONFIGS="/etc/default/activemq"
-+else
-+ ACTIVEMQ_CONFIGS="/etc/default/activemq-$INSTANCE"
-+ echo "INFO: Using alternative activemq configuration files: $ACCTIVEMQ_CONFIGS"
-+fi
- # Backup invocation parameters
- COMMANDLINE_ARGS="$@"
-@@ -50,47 +55,17 @@
+-# Backup invocation parameters
+-COMMANDLINE_ARGS="$@"
++ACTIVEMQ_CONFIGS="/usr/share/activemq/activemq-options"
+
+-# 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: $ACCTIVEMQ_CONFIGS"
++if [ -r "/etc/activemq/instances-enabled/$INSTANCE/options" ]; then
++ ACTIVEMQ_CONFIGS="/etc/activemq/instances-enabled/$INSTANCE/options"
+ fi
+
++# Backup invocation parameters
++COMMANDLINE_ARGS="$@"
++
+ ## START:DEFAULTCONFIG
+ # ------------------------------------------------------------------------
+ # Configuration file for running Apache Active MQ as standalone provider
+@@ -50,71 +48,34 @@ fi
# Active MQ installation dir
if [ -z "$ACTIVEMQ_HOME" ] ; then
# try to find ACTIVEMQ
@@ -72,12 +87,16 @@ Forwarded: not-needed
# Active MQ configuration directory
-ACTIVEMQ_CONFIG_DIR="$ACTIVEMQ_BASE/conf"
-+ACTIVEMQ_CONFIG_DIR="/etc/activemq"
-
- # Active MQ configuration directory
+-
+-# Active MQ configuration directory
if [ -z "$ACTIVEMQ_DATA_DIR" ]; then
-@@ -103,18 +78,18 @@
+ ACTIVEMQ_DATA_DIR="$ACTIVEMQ_BASE/data"
+ fi
+-if [ ! -d "$ACTIVEMQ_DATA_DIR" ]; then
+- mkdir $ACTIVEMQ_DATA_DIR
+-fi
+-
# Location of the pidfile
if [ -z "$ACTIVEMQ_PIDFILE" ]; then
- ACTIVEMQ_PIDFILE="$ACTIVEMQ_DATA_DIR/activemq.pid"
@@ -98,3 +117,27 @@ Forwarded: not-needed
# Set jvm memory configuration
ACTIVEMQ_OPTS_MEMORY="-Xms256M -Xmx256M"
+@@ -318,7 +279,6 @@ if [ "${ACTIVEMQ_BASE}" != "${ACTIVEMQ_HOME}" ]; then
+ fi
+
+
+-
+ # ------------------------------------------------------------------------
+ # HELPER FUNCTIONS
+
+@@ -357,6 +317,15 @@ invokeJar(){
+ DOIT_POSTFIX=" - $ACTIVEMQ_USER"
+ echo "INFO: changing to user '$ACTIVEMQ_USER' to invoke java"
+ fi
++
++ # Create data directory and chown to $ACTIVEMQ_USER
++ if [ ! -d "$ACTIVEMQ_DATA_DIR" ]; then
++ mkdir -p $ACTIVEMQ_DATA_DIR
++ if [ -z "$ACTIVEMQ_USER" ]; then
++ chown -R $ACTIVEMQ_USER $ACTIVEMQ_DATA_DIR
++ fi
++ fi
++
+ # Execute java binary
+ if [ -n "$PIDFILE" ] && [ "$PIDFILE" != "stop" ];then
+ $DOIT_PREFIX "$JAVACMD $ACTIVEMQ_OPTS $ACTIVEMQ_DEBUG_OPTS \
diff --git a/debian/patches/init_only_mkdir_afteruser.diff b/debian/patches/init_only_mkdir_afteruser.diff
deleted file mode 100644
index c92f85b..0000000
--- a/debian/patches/init_only_mkdir_afteruser.diff
+++ /dev/null
@@ -1,42 +0,0 @@
-Description: Init script for ActiveMQ
- Create data directory and chown to $ACTIVEMQ_USER
-Author: Damien Raude-Morvan <draz...@debian.org>
-Last-Update: 2011-07-23
-Forwarded: no
---- a/assembly/src/release/bin/activemq
-+++ b/assembly/src/release/bin/activemq
-@@ -72,10 +72,6 @@
- ACTIVEMQ_DATA_DIR="$ACTIVEMQ_BASE/data"
- fi
-
--if [ ! -d "$ACTIVEMQ_DATA_DIR" ]; then
-- mkdir $ACTIVEMQ_DATA_DIR
--fi
--
- # Location of the pidfile
- if [ -z "$ACTIVEMQ_PIDFILE" ]; then
- ACTIVEMQ_PIDFILE="/var/run/activemq.pid"
-@@ -293,7 +289,6 @@
- fi
-
-
--
- # ------------------------------------------------------------------------
- # HELPER FUNCTIONS
-
-@@ -332,6 +327,15 @@
- DOIT_POSTFIX=" - $ACTIVEMQ_USER"
- echo "INFO: changing to user '$ACTIVEMQ_USER' to invoke java"
- fi
-+
-+ # Create data directory and chown to $ACTIVEMQ_USER
-+ if [ ! -d "$ACTIVEMQ_DATA_DIR" ]; then
-+ mkdir -p $ACTIVEMQ_DATA_DIR
-+ if [ -z "$ACTIVEMQ_USER" ]; then
-+ chown -R $ACTIVEMQ_USER $ACTIVEMQ_DATA_DIR
-+ fi
-+ fi
-+
- # Execute java binary
- if [ -n "$PIDFILE" ] && [ "$PIDFILE" != "stop" ];then
- $DOIT_PREFIX "$JAVACMD $ACTIVEMQ_OPTS $ACTIVEMQ_DEBUG_OPTS \
diff --git a/debian/patches/series b/debian/patches/series
index 24bcef8..215555a 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -4,4 +4,3 @@ exclude_geronimo_jca.diff
exclude_spring_osgi.diff
javadoc_links.diff
init_debian_default_values.diff
-init_only_mkdir_afteruser.diff