static FileLock takeDirectoryLock(File directory) {
        FileLock fileLock = new FileLock(new File(directory, ".lock"));
        try {
            if (!fileLock.tryLock()) {
                throw new RuntimeException("Unable to lock " + directory.getAbsolutePath() +
                    ". Please ensure that no broker or controller process is using this " +
                    "directory before proceeding.");
            }
        } catch (Throwable e) {
            fileLock.destroy();
            throw e;
        }
        return fileLock;
    }
Take the FileLock in the given directory.
shell/src/main/java/org/apache/kafka/shell/MetadataShell.java