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 e09475138d..a72ee513c7 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 @@ -102,10 +102,9 @@ public class Artemis { String instance = artemisInstance != null ? artemisInstance.getAbsolutePath() : System.getProperty("artemis.instance"); Cli.CliBuilder builder = Cli.builder("artemis").withDescription("ActiveMQ Artemis Command Line").withCommand(HelpAction.class).withCommand(Producer.class).withCommand(Consumer.class).withCommand(Browse.class).withDefaultCommand(HelpAction.class); - builder.withGroup("data").withDescription("data tools group (print|exp|imp|exp|encode|decode|compact) (example ./artemis data print)"). - withDefaultCommand(HelpData.class).withCommands(PrintData.class, XmlDataExporter.class, XmlDataImporter.class, DecodeJournal.class, EncodeJournal.class, CompactJournal.class); - if (instance != null) { + builder.withGroup("data").withDescription("data tools group (print|exp|imp|exp|encode|decode|compact) (example ./artemis data print)"). + withDefaultCommand(HelpData.class).withCommands(PrintData.class, XmlDataExporter.class, XmlDataImporter.class, DecodeJournal.class, EncodeJournal.class, CompactJournal.class); builder = builder.withCommands(Run.class, Stop.class, Kill.class); } else { diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Configurable.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Configurable.java index f29a3e3731..c4bd2d4d71 100644 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Configurable.java +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Configurable.java @@ -80,13 +80,25 @@ public abstract class Configurable extends ActionAbstract { private static RandomAccessFile serverLockFile = null; private static FileLock serverLockLock = null; - protected static void lock(File journalPlace) throws Exception { - journalPlace.mkdirs(); - File fileLock = new File(journalPlace, "cli.lock"); - RandomAccessFile file = new RandomAccessFile(fileLock, "rw"); - serverLockLock = file.getChannel().tryLock(); - if (serverLockLock == null) { - throw new CLIException("Error: There is another process using the journal at " + journalPlace + ". Cannot start the process!"); + protected static void lockCLI(File lockPlace) throws Exception { + if (lockPlace != null) { + lockPlace.mkdirs(); + File fileLock = new File(lockPlace, "cli.lock"); + RandomAccessFile file = new RandomAccessFile(fileLock, "rw"); + serverLockLock = file.getChannel().tryLock(); + if (serverLockLock == null) { + throw new CLIException("Error: There is another process using the server at " + lockPlace + ". Cannot start the process!"); + } + } + } + + protected File getLockPlace() throws Exception { + String brokerInstance = getBrokerInstance(); + if (brokerInstance != null) { + return new File(new File(brokerInstance),"lock"); + } + else { + 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 d585b90f7a..ca1335624b 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 @@ -66,7 +66,7 @@ public class Run extends Configurable { FileConfiguration fileConfiguration = getFileConfiguration(); - lock(fileConfiguration.getJournalLocation()); + lockCLI(getLockPlace()); Artemis.printBanner(); diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/LockAbstract.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/LockAbstract.java index e451ef5ae7..9a6984dc53 100644 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/LockAbstract.java +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/LockAbstract.java @@ -17,8 +17,6 @@ package org.apache.activemq.artemis.cli.commands.tools; -import java.io.File; - import org.apache.activemq.artemis.cli.commands.Action; import org.apache.activemq.artemis.cli.commands.ActionContext; @@ -26,7 +24,7 @@ public abstract class LockAbstract extends DataAbstract implements Action { @Override public Object execute(ActionContext context) throws Exception { super.execute(context); - lock(new File(getJournal())); + lockCLI(getLockPlace()); return null; }