You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ch...@apache.org on 2011/04/25 20:36:59 UTC
svn commit: r1096553 - in
/activemq/activemq-apollo/trunk/apollo-cli/src/main:
resources/org/apache/activemq/apollo/cli/commands/bin/apollo-broker-service
scala/org/apache/activemq/apollo/cli/commands/Create.scala
Author: chirino
Date: Mon Apr 25 18:36:59 2011
New Revision: 1096553
URL: http://svn.apache.org/viewvc?rev=1096553&view=rev
Log:
Implemented an apollo-broker-service script which can be used to start/stop and manage a broker that is run in the background.
Added:
activemq/activemq-apollo/trunk/apollo-cli/src/main/resources/org/apache/activemq/apollo/cli/commands/bin/apollo-broker-service
Modified:
activemq/activemq-apollo/trunk/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/commands/Create.scala
Added: activemq/activemq-apollo/trunk/apollo-cli/src/main/resources/org/apache/activemq/apollo/cli/commands/bin/apollo-broker-service
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-cli/src/main/resources/org/apache/activemq/apollo/cli/commands/bin/apollo-broker-service?rev=1096553&view=auto
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-cli/src/main/resources/org/apache/activemq/apollo/cli/commands/bin/apollo-broker-service (added)
+++ activemq/activemq-apollo/trunk/apollo-cli/src/main/resources/org/apache/activemq/apollo/cli/commands/bin/apollo-broker-service Mon Apr 25 18:36:59 2011
@@ -0,0 +1,134 @@
+#!/bin/sh
+# ------------------------------------------------------------------------
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ------------------------------------------------------------------------
+
+APOLLO_USER="${user}"
+service=`basename "$0"`
+
+#
+# Discover the APOLLO_BASE from the location of this script.
+#
+if [ -z "$APOLLO_BASE" ] ; then
+
+ ## resolve links - $0 may be a link to apollo's home
+ PRG="$0"
+ saveddir=`pwd`
+
+ # need this for relative symlinks
+ dirname_prg=`dirname "$PRG"`
+ cd "$dirname_prg"
+
+ while [ -h "$PRG" ] ; do
+ ls=`ls -ld "$PRG"`
+ link=`expr "$ls" : '.*-> \(.*\)$'`
+ if expr "$link" : '.*/.*' > /dev/null; then
+ PRG="$link"
+ else
+ PRG=`dirname "$PRG"`"/$link"
+ fi
+ done
+
+ APOLLO_BASE=`dirname "$PRG"`
+ cd "$saveddir"
+
+ # make it fully qualified
+ APOLLO_BASE=`cd "$APOLLO_BASE/.." && pwd`
+ export APOLLO_BASE
+
+fi
+
+PID_FILE="${APOLLO_BASE}/data/apollo.pid"
+
+stop() {
+ if [ -f ${PID_FILE} ] ; then
+ pid=`cat "${PID_FILE}"`
+ kill $@ ${pid}
+
+ # check to see if it's gone...
+ for i in 1 2 3 4 5 ; do
+ ps -p ${pid} > /dev/null
+ if [ $? -ne 0 ] ; then
+ rm "${PID_FILE}"
+ exit 0
+ fi
+ sleep 1
+ done
+
+ echo Could not stop process ${pid}
+ exit 1
+ fi
+}
+
+start() {
+ if [ -z "$APOLLO_USER" ] ; then
+ nohup ${APOLLO_BASE}/bin/apollo-broker run > /dev/null 2> /dev/null &
+ else
+ sudo -u ${APOLLO_USER} nohup ${APOLLO_BASE}/bin/apollo-broker run > /dev/null 2> /dev/null &
+ fi
+ rc=$?
+ if [ $rc -eq 0 ] ; then
+ echo $! > "${PID_FILE}"
+ else
+ exit $rc
+ fi
+}
+
+case $1 in
+ start)
+ echo "Starting ${service}"
+ start
+ ;;
+
+ force-stop)
+ echo "Forcibly Stopping ${service}"
+ stop -9
+ exit 0
+ ;;
+
+ stop)
+ echo "Gracefully Stopping ${service}"
+ stop
+ exit 0
+ ;;
+
+ restart)
+ echo "Restarting ${service}"
+ stop
+ start
+ exit 0
+ ;;
+
+ status)
+ if [ -f ${PID_FILE} ] ; then
+ pid=`cat "${PID_FILE}"`
+ # check to see if it's gone...
+ ps -p ${pid} > /dev/null
+ if [[ $? -ne 0 ]] ; then
+ echo "${service} is stopped"
+ else
+ echo "${service} is running"
+ fi
+ else
+ echo "${service} is stopped"
+ fi
+ exit 0
+ ;;
+
+ *)
+ echo "Usage: $0 {start|stop|restart|force-stop|status}" >&2
+ exit 2
+esac
Modified: activemq/activemq-apollo/trunk/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/commands/Create.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/commands/Create.scala?rev=1096553&r1=1096552&r2=1096553&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/commands/Create.scala (original)
+++ activemq/activemq-apollo/trunk/apollo-cli/src/main/scala/org/apache/activemq/apollo/cli/commands/Create.scala Mon Apr 25 18:36:59 2011
@@ -107,6 +107,10 @@ class Create extends Action {
target = bin / "apollo-broker"
write("bin/apollo-broker", target, true)
setExecutable(target)
+
+ target = bin / "apollo-broker-service"
+ write("bin/apollo-broker-service", target, true)
+ setExecutable(target)
}
val data = directory / "data"
@@ -123,6 +127,14 @@ class Create extends Action {
println("You can now start the broker by executing: ")
println("")
println(" %s run".format((bin/"apollo-broker").getCanonicalPath))
+ if( !IS_WINDOWS ) {
+ val service = bin / "apollo-broker-service"
+ println("")
+ println("Or you can setup the broker as system service and run it using:")
+ println("")
+ println(" sudo ln -s %s /etc/init.d/".format(service.getCanonicalPath))
+ println(" /etc/init.d/apollo-broker-service start")
+ }
println("")
@@ -156,6 +168,7 @@ class Create extends Action {
var content = new String(out.toByteArray, "UTF-8")
if( filter ) {
+ content = content.replaceAll(Pattern.quote("${user}"), System.getProperty("user.name",""))
content = content.replaceAll(Pattern.quote("${host}"), Matcher.quoteReplacement(host))
content = content.replaceAll(Pattern.quote("${version}"), Matcher.quoteReplacement(Broker.version))
val home = new File(System.getProperty("apollo.home"))