public static boolean validate(File configFile) throws IOException {
log.info("Doing haproxy validate");
ProcessBuilder pb = new ProcessBuilder(HAPROXY_CMD.getAbsolutePath(), "-c", "-f", configFile.getAbsolutePath());
ProcessExecution execution = Processes.run(pb, TimeSpan.seconds(10));
if (!execution.didExit()) {
log.warn("Timeout while validating haproxy config.");
} else {
int exitCode = execution.getExitCode();
if (exitCode == 0) {
log.info("Validated config file");
return true;
} else {
log.warn("Error validating haproxy config. Exit code {}", exitCode);
String config = Files.toString(configFile, Charsets.UTF_8);
log.warn("Bad haproxy config: {}", config);
}
}
log.warn("stdout: {}", execution.getStdout());
log.warn("stderr: {}", execution.getStderr());
return false;
}