Skip to content

Commit

Permalink
[fix][broker] Fix misleading -c option in pulsar standalone (apache#1…
Browse files Browse the repository at this point in the history
…6838)

Motivation
The -c option offered in the standalone is missleading.
An error occurs when pass --config

Modification
* Add `-Dpulsar.config.file` to specify the pulsar standalone config file
* The priority for config file loading: using `-c or --config` > using `-Dpulsar.config.file`
  • Loading branch information
RobertIndie authored Aug 1, 2022
1 parent 99fbe22 commit 3f109d6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion bin/pulsar
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ elif [ $COMMAND == "functions-worker" ]; then
exec $JAVA $OPTS -Dpulsar.log.file=$PULSAR_LOG_FILE org.apache.pulsar.functions.worker.FunctionWorkerStarter -c $PULSAR_WORKER_CONF $@
elif [ $COMMAND == "standalone" ]; then
PULSAR_LOG_FILE=${PULSAR_LOG_FILE:-"pulsar-standalone.log"}
exec $JAVA $LOG4J2_SHUTDOWN_HOOK_DISABLED $OPTS ${ZK_OPTS} -Dpulsar.log.file=$PULSAR_LOG_FILE org.apache.pulsar.PulsarStandaloneStarter --config $PULSAR_STANDALONE_CONF $@
exec $JAVA $LOG4J2_SHUTDOWN_HOOK_DISABLED $OPTS ${ZK_OPTS} -Dpulsar.log.file=$PULSAR_LOG_FILE -Dpulsar.config.file=$PULSAR_STANDALONE_CONF org.apache.pulsar.PulsarStandaloneStarter $@
elif [ ${COMMAND} == "autorecovery" ]; then
PULSAR_LOG_FILE=${PULSAR_LOG_FILE:-"pulsar-autorecovery.log"}
exec $JAVA $OPTS -Dpulsar.log.file=$PULSAR_LOG_FILE org.apache.bookkeeper.replication.AutoRecoveryMain --conf $PULSAR_BOOKKEEPER_CONF $@
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public boolean isHelp() {
return help;
}

@Parameter(names = { "-c", "--config" }, description = "Configuration file path", required = true)
@Parameter(names = { "-c", "--config" }, description = "Configuration file path")
private String configFile;

@Parameter(names = { "--wipe-data" }, description = "Clean up previous ZK/BK data")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static org.apache.commons.lang3.StringUtils.isBlank;
import com.beust.jcommander.JCommander;
import com.beust.jcommander.Parameter;
import com.google.common.base.Strings;
import java.io.FileInputStream;
import java.util.Arrays;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -32,6 +33,9 @@

@Slf4j
public class PulsarStandaloneStarter extends PulsarStandalone {

private static final String PULSAR_CONFIG_FILE = "pulsar.config.file";

@Parameter(names = {"-g", "--generate-docs"}, description = "Generate docs")
private boolean generateDocs = false;

Expand All @@ -41,9 +45,18 @@ public PulsarStandaloneStarter(String[] args) throws Exception {
try {
jcommander.addObject(this);
jcommander.parse(args);
if (this.isHelp() || isBlank(this.getConfigFile())) {
if (this.isHelp()) {
jcommander.usage();
return;
System.exit(0);
}
if (Strings.isNullOrEmpty(this.getConfigFile())) {
String configFile = System.getProperty(PULSAR_CONFIG_FILE);
if (Strings.isNullOrEmpty(configFile)) {
throw new IllegalArgumentException(
"Config file not specified. Please use -c, --config-file or -Dpulsar.config.file to "
+ "specify the config file.");
}
this.setConfigFile(configFile);
}
if (this.generateDocs) {
CmdGenerateDocs cmd = new CmdGenerateDocs("pulsar");
Expand All @@ -60,7 +73,7 @@ public PulsarStandaloneStarter(String[] args) throws Exception {
} catch (Exception e) {
jcommander.usage();
log.error(e.getMessage());
return;
System.exit(1);
}

try (FileInputStream inputStream = new FileInputStream(this.getConfigFile())) {
Expand Down

0 comments on commit 3f109d6

Please sign in to comment.