I'm writing a java application that injects data into Elastic and displays Kibana in an embedded browser window. During initialization, it attempts to start the services for both. The init code for that looks like this:
Logging.logInfo("Starting Elastic service");
try
{
gElastic = new Elastic();
}
catch (IOException ioEx)
{
Logging.showError(this, ioEx, "Failed to start Elastic service", "Critical Error");
exit(EXIT_CRITICAL_FAILURE);
}
while (!gElastic.gReady)
{
DateTime.wait(DateTime.HALF_SECOND);
}
DateTime.wait(DateTime.ONE_SECOND);
Logging.logInfo("Starting Kibana service");
try
{
gKibana = new Kibana();
}
catch (IOException ioEx)
{
Logging.showError(this, ioEx, "Failed to start Kibana service", "Critical Error");
exit(EXIT_CRITICAL_FAILURE);
}
while (!gKibana.gReady)
{
DateTime.wait(DateTime.HALF_SECOND);
}
DateTime.wait(DateTime.ONE_SECOND);
The code that handles the services looks like this:
public static final String KIBANA_BASH = String.format("bash %skibana%sbin%skibana", System.getProperty("user.dir"), File.separator, File.separator);
public Process gProc;
public boolean gReady = false;
public Kibana() throws IOException
{
gProc = Runtime.getRuntime().exec(KIBANA_BASH);
new Threading(() ->
{
try
{
FileOutputStream fos = new FileOutputStream(new File(System.getProperty("user.dir") + "kibana.txt"));
PrintWriter pw = new PrintWriter(fos, true);
Scanner scan = new Scanner(gProc.getInputStream());
while (gProc.isAlive() && !gReady)
{
if (scan.hasNext())
{
String line = scan.nextLine();
pw.println(line);
if (line.trim().endsWith("\"http server running\"}"))
{
gReady = true;
Logging.logInfo("Kibana service ready");
}
}
else
{
DateTime.wait(DateTime.HALF_SECOND);
}
}
scan.close();
pw.flush();
pw.close();
fos.close();
}
catch (Exception ex)
{
Logging.logError(ex, "");
}
});
}
public void close()
{
if (gProc.isAlive())
{
gProc.destroy();
}
}
The Elastic class is identical to the Kibana one except that it runs /elasticsearch/bin/elasticsearch instead of kibana/bin/kibana.
If I use the terminal to start the two services, they both work exactly as expected. Using the above method to start them results in Elastic working as expected - I'm able to navigate to the page and see the JSON output - but going to localhost:5601 results in failure to connect even using a standard browser.
The PrintWriter that you can see in the code is there to dump the console output into a file, and by performing a diff on the output from the regular console and the java console I know that with the exception of time stamps and process numbers they are exactly identical. This leads me to believe that either something on the java side is blocking connections to Kibana, although I can't imagine why it would allow connections to Elastic in that case, or something about my (default) Kibana config doesn't like being started by java and doesn't show in the logs.