80
80
import java .util .*;
81
81
import java .util .concurrent .CountDownLatch ;
82
82
import java .util .concurrent .TimeUnit ;
83
+ import java .util .stream .Stream ;
84
+
83
85
import io .micrometer .core .instrument .binder .jvm .ClassLoaderMetrics ;
84
86
import io .micrometer .core .instrument .binder .jvm .JvmGcMetrics ;
85
87
import io .micrometer .core .instrument .binder .jvm .JvmMemoryMetrics ;
@@ -161,10 +163,11 @@ public class Q2 implements FileFilter, Runnable {
161
163
private long shutdownHookDelay = 0L ;
162
164
public Q2 (String [] args ) {
163
165
super ();
164
- this .args = args ;
166
+ parseCmdLine (args , true );
167
+ this .args = environmentArgs (args );
165
168
startTime = Instant .now ();
166
169
instanceId = UUID .randomUUID ();
167
- parseCmdLine (args );
170
+ parseCmdLine (this . args , false );
168
171
libDir = new File (deployDir , "lib" );
169
172
dirMap = new TreeMap <>();
170
173
deployDir .mkdirs ();
@@ -710,7 +713,7 @@ private static String getLicensee() {
710
713
}
711
714
return s ;
712
715
}
713
- private void parseCmdLine (String [] args ) {
716
+ private void parseCmdLine (String [] args , boolean environmentOnly ) {
714
717
CommandLineParser parser = new DefaultParser ();
715
718
716
719
Options options = new Options ();
@@ -743,6 +746,17 @@ private void parseCmdLine (String[] args) {
743
746
System .setProperty ("log4j2.formatMsgNoLookups" , "true" ); // log4shell prevention
744
747
745
748
CommandLine line = parser .parse (options , args );
749
+ // set up envdir and env before other parts of the system, so env is available
750
+ // force reload if any of the env options was changed
751
+ if (line .hasOption ("Ed" )) {
752
+ System .setProperty ("jpos.envdir" , line .getOptionValue ("Ed" ));
753
+ }
754
+ if (line .hasOption ("E" )) {
755
+ System .setProperty ("jpos.env" , ISOUtil .commaEncode (line .getOptionValues ("E" )));
756
+ }
757
+
758
+ if (environmentOnly )
759
+
746
760
if (line .hasOption ("v" )) {
747
761
displayVersion ();
748
762
System .exit (0 );
@@ -753,14 +767,6 @@ private void parseCmdLine (String[] args) {
753
767
System .exit (0 );
754
768
}
755
769
756
- // set up envdir and env before other parts of the system, so env is available
757
- // force reload if any of the env options was changed
758
- if (line .hasOption ("Ed" )) {
759
- System .setProperty ("jpos.envdir" , line .getOptionValue ("Ed" ));
760
- }
761
- if (line .hasOption ("E" )) {
762
- System .setProperty ("jpos.env" , ISOUtil .commaEncode (line .getOptionValues ("E" )));
763
- }
764
770
765
771
if (line .hasOption ("c" )) {
766
772
cli = new CLI (this , line .getOptionValue ("c" ), line .hasOption ("i" ));
@@ -1237,4 +1243,12 @@ private void registerMicroMeter () {
1237
1243
new JvmThreadMetrics ().bindTo (meterRegistry );
1238
1244
meterRegistry .add (prometheusRegistry );
1239
1245
}
1246
+
1247
+ public String [] environmentArgs (String [] args ) {
1248
+ String envArgs = Environment .getEnvironment ().getProperty ("${q2.args}" , null );
1249
+ return (envArgs != null ?
1250
+ Stream .concat (
1251
+ Arrays .stream (ISOUtil .commaDecode (envArgs )), Arrays .stream (args ))
1252
+ .toArray (String []::new ) : args );
1253
+ }
1240
1254
}
0 commit comments