package com.frederikam.fred.moe;

import com.frederikam.fred.moe.util.SLF4JInputStreamLogger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;

public class Caddy extends Thread {

    private static final Logger log = LoggerFactory.getLogger(Caddy.class);

    public Caddy() {
        setName("Caddy");
    }

    @Override
    public void run() {
        try {
            log.info("Starting Caddy");

            Runtime rt = Runtime.getRuntime();
            Process proc = rt.exec("caddy -conf Caddyfile -agree -email $CADDY_EMAIL");
            new SLF4JInputStreamLogger(log, proc.getInputStream()).start();

            try {
                int code = proc.waitFor();
                log.warn("Exited with code " + code);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        } catch (IOException e) {
            log.warn(e.getMessage());
        }
    }
}

@@ -451,85 +451,88 @@
     
-Runtime rt = Runtime.getRuntime();%0A            Process proc = rt.exec
+ProcessBuilder pb = new ProcessBuilder()%0A                    .command
 (%22caddy
- 
+%22, %22
 -con
@@ -546,16 +546,22 @@
 file
- 
+%22, %22
 -agree
- 
+%22, %22
 -ema
@@ -575,24 +575,66 @@
 DY_EMAIL%22);%0A
+            Process proc = pb.start();doc%0A
             

Test to see if caddy works now