From b3cb4d86b6b143f388b9785d3967b568f65ed89a Mon Sep 17 00:00:00 2001 From: zacharias Date: Thu, 28 May 2026 13:06:37 +0200 Subject: [PATCH] Added early exit for unreachable Ollama --- .../src/main/java/me/neurodock/core/Core.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Core/src/main/java/me/neurodock/core/Core.java b/Core/src/main/java/me/neurodock/core/Core.java index 3916956..d05961b 100644 --- a/Core/src/main/java/me/neurodock/core/Core.java +++ b/Core/src/main/java/me/neurodock/core/Core.java @@ -401,6 +401,32 @@ public class Core { })); } + /** + * A check to exit early if Ollama isn't reachable. + */ + private void confirmOllama() + { + try { + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("GET"); + connection.setRequestProperty("Content-Type", "application/json"); + connection.setDoOutput(true); + connection.setConnectTimeout(3 * 1000); + + int responseCode = connection.getResponseCode(); + + if (responseCode != HttpURLConnection.HTTP_OK) { + new RuntimeException("Ollama is un-responsive on url: " + url.toString()).printStackTrace(); + System.exit(1); + } + }catch (IOException ex) + { + ex.printStackTrace(); + System.out.println("Can not reach Ollama!"); + System.exit(1); + } + } + /** * Creates a new instance of Core with the provided PrintMessageHandler, * defaulting the Ollama backend to {@code localhost}. @@ -425,6 +451,7 @@ public class Core { initDirectories(); initOllamaUrl(); + confirmOllama(); initLogWriter(); initScheduler(); initShutdownHook();