]> WPIA git - gigi.git/commitdiff
Support reading configuration from file
authorLucas Werkmeister <mail@lucaswerkmeister.de>
Mon, 29 Aug 2016 14:00:47 +0000 (16:00 +0200)
committerLucas Werkmeister <mail@lucaswerkmeister.de>
Mon, 29 Aug 2016 14:14:32 +0000 (16:14 +0200)
This is necessary to support socket activation (Java only supports a
single "inherited channel", which must be file descriptor 0), and also
makes it simpler to run gigi when the configuration is just a regular
file.

It also simplifies the DevelLauncher a bit.

Change-Id: I8bf03317ea549bd17f5b61e50808f48314a06803

src/org/cacert/gigi/Launcher.java
util-testing/org/cacert/gigi/DevelLauncher.java

index a7730adcc9d249350fa555affeb949b109aa919c..cff94772eff804d85593d9f537858ea887dd4254 100644 (file)
@@ -1,6 +1,9 @@
 package org.cacert.gigi;
 
 import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
 import java.io.IOException;
 import java.net.HttpURLConnection;
 import java.net.InetSocketAddress;
@@ -96,19 +99,25 @@ public class Launcher {
 
     public static void main(String[] args) throws Exception {
         System.setProperty("jdk.tls.ephemeralDHKeySize", "4096");
-        new Launcher().boot();
+        InputStream in;
+        if (args.length >= 1) {
+            in = new FileInputStream(new File(args[0]));
+        } else {
+            in = System.in;
+        }
+        new Launcher().boot(in);
     }
 
     Server s;
 
     GigiConfig conf;
 
-    public synchronized void boot() throws Exception {
+    public synchronized void boot(InputStream in) throws Exception {
         Locale.setDefault(Locale.ENGLISH);
         TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
         HttpURLConnection.setFollowRedirects(false);
 
-        conf = GigiConfig.parse(System.in);
+        conf = GigiConfig.parse(in);
         ServerConstants.init(conf.getMainProps());
         initEmails(conf);
 
index 736947d55ac566675d62c25b93d06fa2120058ff..0fe534548aeab7b22c9e6ad030692f21e7e87c92 100644 (file)
@@ -70,9 +70,7 @@ public class DevelLauncher {
 
         DevelLauncher.writeGigiConfig(dos, "changeit".getBytes("UTF-8"), "changeit".getBytes("UTF-8"), mainProps, cacerts, keystore);
         dos.flush();
-        InputStream oldin = System.in;
-        System.setIn(new ByteArrayInputStream(chunkConfig.toByteArray()));
-        new Launcher().boot();
+        new Launcher().boot(new ByteArrayInputStream(chunkConfig.toByteArray()));
         addDevelPage(true);
         new Thread("ticket awaiter") {
 
@@ -94,7 +92,6 @@ public class DevelLauncher {
                 }
             }
         }.start();
-        System.setIn(oldin);
         BufferedReader br = new BufferedReader(new InputStreamReader(System.in, "UTF-8"));
         System.out.println("Cacert-gigi system sucessfully started.");
         System.out.println("Press enter to shutdown.");