From da66c468477da6475841975c35b7a85fa39f22f0 Mon Sep 17 00:00:00 2001 From: Bruce Snyder Date: Wed, 9 Mar 2011 01:42:36 +0000 Subject: [PATCH] AMQ-2968 - Add Apache commons daemon (jsvc/procrun) start/stop support. git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1079638 13f79535-47bb-0310-9956-ffa450edef68 --- NOTICE | 5 + activemq-console/pom.xml | 8 +- .../activemq/console/ActiveMQLauncher.java | 103 ++++++++++++++++++ pom.xml | 17 ++- 4 files changed, 127 insertions(+), 6 deletions(-) create mode 100644 activemq-console/src/main/java/org/apache/activemq/console/ActiveMQLauncher.java diff --git a/NOTICE b/NOTICE index 490a72f4e4..4706e52508 100644 --- a/NOTICE +++ b/NOTICE @@ -42,3 +42,8 @@ Some portions of the code are Copyright: 1999 Jason Gilbert. The jboss integration module contains some LGPL code. + +This product includes software developed by + Yahoo! Inc. (www.yahoo.com) + Copyright (c) 2010 Yahoo! Inc. All rights reserved. + diff --git a/activemq-console/pom.xml b/activemq-console/pom.xml index e43fdab635..a75cdda0d4 100644 --- a/activemq-console/pom.xml +++ b/activemq-console/pom.xml @@ -125,7 +125,13 @@ com.ibm.icu icu4j - + + + + commons-daemon + commons-daemon + + diff --git a/activemq-console/src/main/java/org/apache/activemq/console/ActiveMQLauncher.java b/activemq-console/src/main/java/org/apache/activemq/console/ActiveMQLauncher.java new file mode 100644 index 0000000000..4527b6facb --- /dev/null +++ b/activemq-console/src/main/java/org/apache/activemq/console/ActiveMQLauncher.java @@ -0,0 +1,103 @@ +/** + * 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. + */ + +package org.apache.activemq.console; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.apache.activemq.console.command.Command; +import org.apache.activemq.console.command.ShutdownCommand; +import org.apache.activemq.console.command.StartCommand; +import org.apache.activemq.console.CommandContext; +import org.apache.activemq.console.Main; +import org.apache.activemq.console.formatter.CommandShellOutputFormatter; +import org.apache.commons.daemon.Daemon; +import org.apache.commons.daemon.DaemonContext; + +/** + * This class launches activemq under Apache JSVC {@link http://commons.apache.org/daemon/jsvc.html} + * + * @author areese + * + */ +public class ActiveMQLauncher implements Daemon { + private List args; + + /** + * + */ + public ActiveMQLauncher() { + } + + /* + * (non-Javadoc) + * + * @see org.apache.commons.daemon.Daemon#destroy() + */ + public void destroy() { + } + + /* + * (non-Javadoc) + * + * @see + * org.apache.commons.daemon.Daemon#init(org.apache.commons.daemon.DaemonContext + * ) + */ + public void init(DaemonContext arg0) throws Exception { + // we need to save the args we started with. + args = Arrays.asList(arg0.getArguments()); + } + + /* + * (non-Javadoc) + * + * @see org.apache.commons.daemon.Daemon#start() + */ + public void start() throws Exception { + CommandContext context = new CommandContext(); + context.setFormatter(new CommandShellOutputFormatter(System.out)); + + Command command = new StartCommand(); + command.setCommandContext(context); + + command.execute(args); + } + + /* + * (non-Javadoc) + * + * @see org.apache.commons.daemon.Daemon#stop() + */ + public void stop() throws Exception { + CommandContext context = new CommandContext(); + context.setFormatter(new CommandShellOutputFormatter(System.out)); + + Command command = new ShutdownCommand(); + command.setCommandContext(context); + + List tokens = new ArrayList(Arrays.asList(new String[] { + "--jmxlocal", "--all", })); + + command.execute(tokens); + } + +} diff --git a/pom.xml b/pom.xml index 2af9ed1774..03fdea6152 100755 --- a/pom.xml +++ b/pom.xml @@ -449,6 +449,13 @@ 3.0.0 true + + + + commons-daemon + commons-daemon + 1.0.3 + @@ -941,11 +948,11 @@ - - commons-net - commons-net - ${commons-net-version} - + + commons-net + commons-net + ${commons-net-version} + org.apache.velocity