Github user fuyou001 commented on a diff in the pull request: https://github.com/apache/incubator-rocketmq/pull/158#discussion_r135705590 --- Diff: broker/src/main/java/org/apache/rocketmq/broker/BrokerStartup.java --- @@ -257,4 +268,28 @@ public static Options buildCommandlineOptions(final Options options) { return options; } + + private static void checkMQAlreadyStart(String storePathRootDir) throws IOException { + File file = new File(StorePathConfigHelper.getLockFile(storePathRootDir)); + MappedFile.ensureDirOK(file.getParent()); + + final RandomAccessFile randomAccessFile = new RandomAccessFile(file, "rw"); + FileLock lock = randomAccessFile.getChannel().tryLock(0, 1, false); + if (lock == null || lock.isShared() || !lock.isValid()) { + throw new RuntimeException("Lock failed,MQ already started"); + } + + randomAccessFile.getChannel().write(ByteBuffer.wrap("lock".getBytes())); + randomAccessFile.getChannel().force(true); + + Runtime.getRuntime().addShutdownHook(new Thread() { --- End diff -- done
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---