Skip to content

Commit

Permalink
support Q2 arguments via q2.args environment
Browse files Browse the repository at this point in the history
  • Loading branch information
ar committed Mar 16, 2024
1 parent c03744f commit 6f2658d
Showing 1 changed file with 25 additions and 11 deletions.
36 changes: 25 additions & 11 deletions jpos/src/main/java/org/jpos/q2/Q2.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@
import java.util.*;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.stream.Stream;

import io.micrometer.core.instrument.binder.jvm.ClassLoaderMetrics;
import io.micrometer.core.instrument.binder.jvm.JvmGcMetrics;
import io.micrometer.core.instrument.binder.jvm.JvmMemoryMetrics;
Expand Down Expand Up @@ -161,10 +163,11 @@ public class Q2 implements FileFilter, Runnable {
private long shutdownHookDelay = 0L;
public Q2 (String[] args) {
super();
this.args = args;
parseCmdLine (args, true);
this.args = environmentArgs(args);
startTime = Instant.now();
instanceId = UUID.randomUUID();
parseCmdLine (args);
parseCmdLine (this.args, false);
libDir = new File (deployDir, "lib");
dirMap = new TreeMap<>();
deployDir.mkdirs ();
Expand Down Expand Up @@ -710,7 +713,7 @@ private static String getLicensee() {
}
return s;
}
private void parseCmdLine (String[] args) {
private void parseCmdLine (String[] args, boolean environmentOnly) {
CommandLineParser parser = new DefaultParser ();

Options options = new Options ();
Expand Down Expand Up @@ -743,6 +746,17 @@ private void parseCmdLine (String[] args) {
System.setProperty("log4j2.formatMsgNoLookups", "true"); // log4shell prevention

CommandLine line = parser.parse (options, args);
// set up envdir and env before other parts of the system, so env is available
// force reload if any of the env options was changed
if (line.hasOption("Ed")) {
System.setProperty("jpos.envdir", line.getOptionValue("Ed"));
}
if (line.hasOption("E")) {
System.setProperty("jpos.env", ISOUtil.commaEncode(line.getOptionValues("E")));
}

if (environmentOnly)

if (line.hasOption ("v")) {
displayVersion();
System.exit (0);
Expand All @@ -753,14 +767,6 @@ private void parseCmdLine (String[] args) {
System.exit (0);
}

// set up envdir and env before other parts of the system, so env is available
// force reload if any of the env options was changed
if (line.hasOption("Ed")) {
System.setProperty("jpos.envdir", line.getOptionValue("Ed"));
}
if (line.hasOption("E")) {
System.setProperty("jpos.env", ISOUtil.commaEncode(line.getOptionValues("E")));
}

if (line.hasOption ("c")) {
cli = new CLI(this, line.getOptionValue("c"), line.hasOption("i"));
Expand Down Expand Up @@ -1237,4 +1243,12 @@ private void registerMicroMeter () {
new JvmThreadMetrics().bindTo(meterRegistry);
meterRegistry.add (prometheusRegistry);
}

public String[] environmentArgs (String[] args) {
String envArgs = Environment.getEnvironment().getProperty("${q2.args}", null);
return (envArgs != null ?
Stream.concat(
Arrays.stream(ISOUtil.commaDecode(envArgs)), Arrays.stream(args))
.toArray(String[]::new) : args);
}
}

0 comments on commit 6f2658d

Please sign in to comment.