diff --git a/artemis-boot/src/main/java/org/apache/activemq/artemis/boot/Artemis.java b/artemis-boot/src/main/java/org/apache/activemq/artemis/boot/Artemis.java index bf83100f15..ca3699ef74 100644 --- a/artemis-boot/src/main/java/org/apache/activemq/artemis/boot/Artemis.java +++ b/artemis-boot/src/main/java/org/apache/activemq/artemis/boot/Artemis.java @@ -38,11 +38,6 @@ public class Artemis public static void main(String[] args) throws Throwable { ArrayList dirs = new ArrayList(); - String instance = System.getProperty("artemis.instance"); - if (instance != null) - { - dirs.add(new File(new File(instance), "lib")); - } String home = System.getProperty("artemis.home"); if (home != null) @@ -50,6 +45,14 @@ public class Artemis dirs.add(new File(new File(home), "lib")); } + String instance = System.getProperty("artemis.instance"); + File instanceFile = null; + if (instance != null) + { + instanceFile = new File(instance); + dirs.add(new File(instanceFile, "lib")); + } + ArrayList urls = new ArrayList(); for (File bootdir : dirs) { @@ -95,6 +98,14 @@ public class Artemis System.setProperty("logging.configuration", fixupFileURI(loggingConfig)); } + // Without the etc on the config, things like JGroups configuration wouldn't be loaded + if (instanceFile != null) + { + File etcFile = new File(instance, "etc"); + // Adding etc to the classLoader so modules can lookup for their configs + urls.add(etcFile.toURI().toURL()); + } + // Now setup our classloader.. URLClassLoader loader = new URLClassLoader(urls.toArray(new URL[urls.size()])); Thread.currentThread().setContextClassLoader(loader); diff --git a/artemis-cli/pom.xml b/artemis-cli/pom.xml index 5d026c90ec..efc8302bc8 100644 --- a/artemis-cli/pom.xml +++ b/artemis-cli/pom.xml @@ -25,7 +25,7 @@ artemis-cli jar - ActiveMQ Artemis Bootstrap + ActiveMQ Artemis CLI ${project.basedir}/.. diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/Artemis.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/Artemis.java index e5689ca685..0af24ae673 100644 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/Artemis.java +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/Artemis.java @@ -25,6 +25,7 @@ import org.apache.activemq.artemis.cli.commands.Action; import org.apache.activemq.artemis.cli.commands.ActionContext; import org.apache.activemq.artemis.cli.commands.Create; import org.apache.activemq.artemis.cli.commands.HelpAction; +import org.apache.activemq.artemis.cli.commands.Kill; import org.apache.activemq.artemis.cli.commands.Run; import org.apache.activemq.artemis.cli.commands.Stop; import org.apache.activemq.artemis.cli.commands.tools.DecodeJournal; @@ -53,7 +54,7 @@ public class Artemis if (instance != null) { builder = builder - .withCommands(Run.class, Stop.class); + .withCommands(Run.class, Stop.class, Kill.class); } else { @@ -61,7 +62,6 @@ public class Artemis .withCommand(Create.class); } - Cli parser = builder.build(); try { diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Create.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Create.java index c3eb44b205..02b730190b 100644 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Create.java +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Create.java @@ -61,6 +61,8 @@ public class Create implements Action private static final Integer HQ_PORT = 5445; + private static final Integer HTTP_PORT = 8161; + public static final String BIN_ARTEMIS_CMD = "bin/artemis.cmd"; public static final String BIN_ARTEMIS_SERVICE_EXE = "bin/artemis-service.exe"; public static final String BIN_ARTEMIS_SERVICE_XML = "bin/artemis-service.xml"; @@ -107,6 +109,9 @@ public class Create implements Action @Option(name = "--encoding", description = "The encoding that text files should use") String encoding = "UTF-8"; + @Option(name = "--java-options", description = "Extra java options to be passed to the profile") + String javaOptions = ""; + ActionContext context; private Scanner scanner; @@ -115,6 +120,110 @@ public class Create implements Action boolean IS_CYGWIN; + public int getPortOffset() + { + return portOffset; + } + + public void setPortOffset(int portOffset) + { + this.portOffset = portOffset; + } + + public String getJavaOptions() + { + return javaOptions; + } + + public void setJavaOptions(String javaOptions) + { + this.javaOptions = javaOptions; + } + + public File getInstance() + { + return directory; + } + + public void setInstance(File directory) + { + this.directory = directory; + } + + public String getHost() + { + return host; + } + + public void setHost(String host) + { + this.host = host; + } + + public boolean isForce() + { + return force; + } + + public void setForce(boolean force) + { + this.force = force; + } + + public File getHome() + { + if (home == null) + { + home = new File(System.getProperty("artemis.home")); + } + return home; + } + + public void setHome(File home) + { + this.home = home; + } + + public boolean isClustered() + { + return clustered; + } + + public void setClustered(boolean clustered) + { + this.clustered = clustered; + } + + public boolean isReplicated() + { + return replicated; + } + + public void setReplicated(boolean replicated) + { + this.replicated = replicated; + } + + public boolean isSharedStore() + { + return sharedStore; + } + + public void setSharedStore(boolean sharedStore) + { + this.sharedStore = sharedStore; + } + + public String getEncoding() + { + return encoding; + } + + public void setEncoding(String encoding) + { + this.encoding = encoding; + } + @Override public Object execute(ActionContext context) throws Exception { @@ -125,7 +234,7 @@ public class Create implements Action catch (Throwable e) { e.printStackTrace(context.err); - return e; + throw e; } } @@ -209,12 +318,15 @@ public class Create implements Action filters.put("${amqp.port}", String.valueOf(AMQP_PORT + portOffset)); filters.put("${stomp.port}", String.valueOf(STOMP_PORT + portOffset)); filters.put("${hq.port}", String.valueOf(HQ_PORT + portOffset)); + filters.put("${http.port}", String.valueOf(HTTP_PORT + portOffset)); + if (home != null) { filters.put("${home}", path(home, false)); } - filters.put("${artemis.home}", path(System.getProperty("artemis.home"), false)); + filters.put("${artemis.home}", path(getHome().toString(), false)); filters.put("${artemis.instance}", path(directory, false)); + filters.put("${artemis.instance.name}", directory.getName()); filters.put("${java.home}", path(System.getProperty("java.home"), false)); new File(directory, "bin").mkdirs(); @@ -223,6 +335,12 @@ public class Create implements Action new File(directory, "tmp").mkdirs(); new File(directory, "data").mkdirs(); + if (javaOptions == null || javaOptions.length() == 0) + { + javaOptions = ""; + } + + filters.put("${java-opts}", javaOptions); if (IS_WINDOWS) { @@ -243,7 +361,7 @@ public class Create implements Action } write(ETC_LOGGING_PROPERTIES, null, false); - write(ETC_BOOTSTRAP_XML, null, false); + write(ETC_BOOTSTRAP_XML, filters, false); write(ETC_BROKER_XML, filters, false); write(ETC_ARTEMIS_ROLES_PROPERTIES, null, false); write(ETC_ARTEMIS_USERS_PROPERTIES, null, false); @@ -277,17 +395,21 @@ public class Create implements Action context.out.println(String.format(" \"%s\" start", path(service, true))); context.out.println(""); } - } + if (IS_WINDOWS) { - + service = new File(directory, BIN_ARTEMIS_SERVICE_EXE); context.out.println("Or you can setup the broker as Windows service and run it in the background:"); context.out.println(""); context.out.println(String.format(" \"%s\" install", path(service, true))); context.out.println(String.format(" \"%s\" start", path(service, true))); context.out.println(""); - + context.out.println(" To stop the windows service:"); + context.out.println(String.format(" \"%s\" stop", path(service, true))); + context.out.println(""); + context.out.println(" To uninstall the windows service"); + context.out.println(String.format(" \"%s\" uninstall", path(service, true))); } return null; diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Kill.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Kill.java new file mode 100644 index 0000000000..675d28c229 --- /dev/null +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Kill.java @@ -0,0 +1,41 @@ +/** + * 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.artemis.cli.commands; + +import java.io.File; + +import io.airlift.airline.Command; +import org.apache.activemq.artemis.dto.BrokerDTO; + +@Command(name = "kill", description = "Kills a broker instance started with --allow-kill") +public class Kill extends Configurable implements Action +{ + @Override + public Object execute(ActionContext context) throws Exception + + { + BrokerDTO broker = getBrokerDTO(); + + File file = broker.server.getConfigurationFile().getParentFile(); + + File killFile = new File(file, "KILL_ME"); + + killFile.createNewFile(); + + return null; + } +} diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Run.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Run.java index 8a278e78b5..2ae98c4907 100644 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Run.java +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Run.java @@ -22,6 +22,7 @@ import java.util.Timer; import java.util.TimerTask; import io.airlift.airline.Command; +import io.airlift.airline.Option; import org.apache.activemq.artemis.cli.Artemis; import org.apache.activemq.artemis.components.ExternalComponent; import org.apache.activemq.artemis.core.server.ActiveMQComponent; @@ -36,6 +37,8 @@ import org.apache.activemq.artemis.spi.core.security.ActiveMQSecurityManager; @Command(name = "run", description = "runs the broker instance") public class Run extends Configurable implements Action { + @Option(name = "--allow-kill", description = "This will allow the server to kill itself. Useful for tests (failover tests for instance)") + boolean allowKill; private Broker server; @@ -88,12 +91,33 @@ public class Run extends Configurable implements Action ActiveMQBootstrapLogger.LOGGER.errorDeletingFile(file.getAbsolutePath()); } } + final File fileKill = new File(configurationDir,"KILL_ME"); + if (fileKill.exists()) + { + if (!fileKill.delete()) + { + ActiveMQBootstrapLogger.LOGGER.errorDeletingFile(fileKill.getAbsolutePath()); + } + } + final Timer timer = new Timer("ActiveMQ Artemis Server Shutdown Timer", true); timer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { + if (allowKill && fileKill.exists()) + { + try + { + System.err.println("Halting by user request"); + fileKill.delete(); + } + catch (Throwable ignored) + { + } + Runtime.getRuntime().halt(0); + } if (file.exists()) { try @@ -116,5 +140,22 @@ public class Run extends Configurable implements Action } } }, 500, 500); + + + Runtime.getRuntime().addShutdownHook(new Thread() + { + public void run() + { + try + { + server.stop(); + } + catch (Exception e) + { + e.printStackTrace(); + } + } + }); + } } diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/integration/bootstrap/ActiveMQBootstrapLogger.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/integration/bootstrap/ActiveMQBootstrapLogger.java index dc6d0deb04..b2249b3f2d 100644 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/integration/bootstrap/ActiveMQBootstrapLogger.java +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/integration/bootstrap/ActiveMQBootstrapLogger.java @@ -57,6 +57,10 @@ public interface ActiveMQBootstrapLogger extends BasicLogger @Message(id = 101002, value = "Starting Naming server on {0}:{1,number,#} (rmi {2}:{3,number,#})", format = Message.Format.MESSAGE_FORMAT) void startedNamingService(String bindAddress, int port, String rmiBindAddress, int rmiPort); + @LogMessage(level = Logger.Level.INFO) + @Message(id = 101003, value = "Halting ActiveMQ Artemis Server after user request", format = Message.Format.MESSAGE_FORMAT) + void serverKilled(); + @LogMessage(level = Logger.Level.WARN) @Message(id = 102000, value = "Error during undeployment: {0}", format = Message.Format.MESSAGE_FORMAT) void errorDuringUndeployment(@Cause Throwable t, String name); diff --git a/artemis-cli/src/main/resources/org/apache/activemq/artemis/cli/commands/bin/artemis b/artemis-cli/src/main/resources/org/apache/activemq/artemis/cli/commands/bin/artemis index c5e973e24a..4173f8743d 100755 --- a/artemis-cli/src/main/resources/org/apache/activemq/artemis/cli/commands/bin/artemis +++ b/artemis-cli/src/main/resources/org/apache/activemq/artemis/cli/commands/bin/artemis @@ -48,7 +48,6 @@ fi ARTEMIS_LOGGING_CONF="file:$ARTEMIS_INSTANCE/etc/logging.properties" ARTEMIS_DATA_DIR="$ARTEMIS_INSTANCE/data" ARTEMIS_LOG_MANAGER=org.jboss.logmanager.LogManager -JAVA_ARGS="-XX:+UseParallelGC -XX:+AggressiveOpts -XX:+UseFastAccessorMethods -Xms512M -Xmx1024M" # Load Profile Data . "$ARTEMIS_INSTANCE/etc/artemis.profile" @@ -116,4 +115,4 @@ exec "$JAVACMD" $JAVA_ARGS $ARTEMIS_CLUSTER_PROPS \ -Djava.util.logging.manager="$ARTEMIS_LOG_MANAGER" \ -Dlogging.configuration="$ARTEMIS_LOGGING_CONF" \ $DEBUG_ARGS \ - org.apache.activemq.artemis.boot.Artemis $@ + org.apache.activemq.artemis.boot.Artemis "$@" diff --git a/artemis-cli/src/main/resources/org/apache/activemq/artemis/cli/commands/bin/artemis-service.xml b/artemis-cli/src/main/resources/org/apache/activemq/artemis/cli/commands/bin/artemis-service.xml index a39d16f943..3828dd09db 100644 --- a/artemis-cli/src/main/resources/org/apache/activemq/artemis/cli/commands/bin/artemis-service.xml +++ b/artemis-cli/src/main/resources/org/apache/activemq/artemis/cli/commands/bin/artemis-service.xml @@ -18,14 +18,14 @@ --> - armetis-${host} - ActiveMQ Artemis: ${host} + armetis-${artemis.instance.name}-${host} + ActiveMQ Artemis: ${artemis.instance.name} @ ${host} Apache ActiveMQ Artemis is a reliable messaging broker ${artemis.instance}\log roll - "${java.home}\bin\java.exe" + java -XX:+UseParallelGC -XX:+AggressiveOpts -XX:+UseFastAccessorMethods @@ -41,18 +41,18 @@ -classpath "${artemis.home}\lib\artemis-boot.jar" - "-artemis.home=${artemis.home}" - "-artemis.instance=${artemis.instance}" - "-Ddata.dir=${artemis.instance}/data" + -Dartemis.home="${artemis.home}" + -Dartemis.instance="${artemis.instance}" + -Ddata.dir="${artemis.instance}/data" -Djava.util.logging.manager=org.jboss.logmanager.LogManager - "-Dlogging.configuration=file:${artemis.instance}\etc\logging.properties" + -Dlogging.configuration="file:${artemis.instance}\etc\logging.properties" - Armetis + org.apache.activemq.artemis.boot.Artemis run diff --git a/artemis-cli/src/main/resources/org/apache/activemq/artemis/cli/commands/bin/artemis.cmd b/artemis-cli/src/main/resources/org/apache/activemq/artemis/cli/commands/bin/artemis.cmd index c9384ca181..809adfe27d 100755 --- a/artemis-cli/src/main/resources/org/apache/activemq/artemis/cli/commands/bin/artemis.cmd +++ b/artemis-cli/src/main/resources/org/apache/activemq/artemis/cli/commands/bin/artemis.cmd @@ -48,7 +48,6 @@ echo. :RUN_JAVA rem "Set Defaults." -set JAVA_ARGS=-XX:+UseParallelGC -XX:+AggressiveOpts -XX:+UseFastAccessorMethods -Xms512M -Xmx1024M set ARTEMIS_LOGGING_CONF=file:%ARTEMIS_INSTANCE%\etc\logging.properties set ARTEMIS_DATA_DIR=%ARTEMIS_INSTANCE%\data set ARTEMIS_LOG_MANAGER=org.jboss.logmanager.LogManager diff --git a/artemis-cli/src/main/resources/org/apache/activemq/artemis/cli/commands/etc/artemis.profile b/artemis-cli/src/main/resources/org/apache/activemq/artemis/cli/commands/etc/artemis.profile index 889a0a9eec..937a1f972a 100644 --- a/artemis-cli/src/main/resources/org/apache/activemq/artemis/cli/commands/etc/artemis.profile +++ b/artemis-cli/src/main/resources/org/apache/activemq/artemis/cli/commands/etc/artemis.profile @@ -20,8 +20,11 @@ ARTEMIS_HOME='${artemis.home}' # Cluster Properties: Used to pass arguments to ActiveMQ which can be referenced in broker.xml #ARTEMIS_CLUSTER_PROPS="-Dactivemq.remoting.default.port=61617 -Dactivemq.remoting.amqp.port=5673 -Dactivemq.remoting.stomp.port=61614 -Dactivemq.remoting.hornetq.port=5446" + + # Java Opts -#JAVA_ARGS="-XX:+UseParallelGC -XX:+AggressiveOpts -XX:+UseFastAccessorMethods -Xms512M -Xmx1024M" +JAVA_ARGS="-XX:+UseParallelGC -XX:+AggressiveOpts -XX:+UseFastAccessorMethods -Xms512M -Xmx1024M ${java-opts}" + # Debug args: Uncomment to enable debug #DEBUG_ARGS="-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005" diff --git a/artemis-cli/src/main/resources/org/apache/activemq/artemis/cli/commands/etc/artemis.profile.cmd b/artemis-cli/src/main/resources/org/apache/activemq/artemis/cli/commands/etc/artemis.profile.cmd index 450ba792dc..fc9ce0c0e5 100644 --- a/artemis-cli/src/main/resources/org/apache/activemq/artemis/cli/commands/etc/artemis.profile.cmd +++ b/artemis-cli/src/main/resources/org/apache/activemq/artemis/cli/commands/etc/artemis.profile.cmd @@ -21,7 +21,7 @@ rem Cluster Properties: Used to pass arguments to ActiveMQ which can be referenc rem set ARTEMIS_CLUSTER_PROPS=-Dactivemq.remoting.default.port=61617 -Dactivemq.remoting.amqp.port=5673 -Dactivemq.remoting.stomp.port=61614 -Dactivemq.remoting.hornetq.port=5446 rem Java Opts -rem set JAVA_ARGS=-XX:+UseParallelGC -XX:+AggressiveOpts -XX:+UseFastAccessorMethods -Xms512M -Xmx1024M +set JAVA_ARGS=-XX:+UseParallelGC -XX:+AggressiveOpts -XX:+UseFastAccessorMethods -Xms512M -Xmx1024M ${java-opts} rem Debug args: Uncomment to enable debug rem set DEBUG_ARGS=-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005 diff --git a/artemis-cli/src/main/resources/org/apache/activemq/artemis/cli/commands/etc/bootstrap.xml b/artemis-cli/src/main/resources/org/apache/activemq/artemis/cli/commands/etc/bootstrap.xml index 21d174f171..52a459b482 100644 --- a/artemis-cli/src/main/resources/org/apache/activemq/artemis/cli/commands/etc/bootstrap.xml +++ b/artemis-cli/src/main/resources/org/apache/activemq/artemis/cli/commands/etc/bootstrap.xml @@ -26,7 +26,7 @@ - +