Port distributions and start scripts to Undertow
This commit is contained in:
@@ -22,19 +22,48 @@ package io.kamax.mxisd;
|
||||
|
||||
import io.kamax.mxisd.config.MxisdConfig;
|
||||
import io.kamax.mxisd.config.YamlConfigLoader;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.Objects;
|
||||
|
||||
public class MxisdStandaloneExec {
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
// FIXME no hard-coding, make it configurable via Build, Env and CLI parameters
|
||||
MxisdConfig cfg = YamlConfigLoader.loadFromFile("mxisd.yaml");
|
||||
HttpMxisd mxisd = new HttpMxisd(cfg);
|
||||
MxisdConfig cfg = null;
|
||||
|
||||
Runtime.getRuntime().addShutdownHook(new Thread(mxisd::stop));
|
||||
Iterator<String> argsIt = Arrays.asList(args).iterator();
|
||||
while (argsIt.hasNext()) {
|
||||
String arg = argsIt.next();
|
||||
if (StringUtils.equals("-c", arg)) {
|
||||
String cfgFile = argsIt.next();
|
||||
cfg = YamlConfigLoader.loadFromFile(cfgFile);
|
||||
System.out.println("Loaded configuration from " + cfgFile);
|
||||
} else {
|
||||
System.out.println("Invalid argument: " + arg);
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
mxisd.start();
|
||||
if (Objects.isNull(cfg)) {
|
||||
cfg = YamlConfigLoader.tryLoadFromFile("mxisd.yaml").orElseGet(MxisdConfig::new);
|
||||
}
|
||||
|
||||
try {
|
||||
HttpMxisd mxisd = new HttpMxisd(cfg);
|
||||
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
||||
mxisd.stop();
|
||||
System.out.println("------------- mxisd stopped -------------");
|
||||
}));
|
||||
mxisd.start();
|
||||
|
||||
System.out.println("------------- mxisd started -------------");
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,7 +26,9 @@ import org.yaml.snakeyaml.constructor.Constructor;
|
||||
import org.yaml.snakeyaml.representer.Representer;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.Optional;
|
||||
|
||||
public class YamlConfigLoader {
|
||||
|
||||
@@ -39,4 +41,14 @@ public class YamlConfigLoader {
|
||||
return GsonUtil.get().fromJson(GsonUtil.get().toJson(o), MxisdConfig.class);
|
||||
}
|
||||
|
||||
public static Optional<MxisdConfig> tryLoadFromFile(String path) {
|
||||
try {
|
||||
return Optional.of(loadFromFile(path));
|
||||
} catch (FileNotFoundException e) {
|
||||
return Optional.empty();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user