diff --git a/src/main/java/com/sixt/service/framework/JettyServiceBase.java b/src/main/java/com/sixt/service/framework/JettyServiceBase.java index 1fa3c9b..acd2b44 100644 --- a/src/main/java/com/sixt/service/framework/JettyServiceBase.java +++ b/src/main/java/com/sixt/service/framework/JettyServiceBase.java @@ -94,18 +94,16 @@ public static void main(String[] args) { //we have to start the container before service registration happens to know the port service.startJettyContainer(); - Annotation[] serviceAnnos = serviceClass.getAnnotations(); - service.initializeServiceRegistration(); - service.verifyEnvironment(); + verifyEnvironmentAndExitIfNeeded(service); //we start health checks first so we can see services with bad state if (!hcProviders.isEmpty()) { service.initializeHealthCheckManager(hcProviders); } - if (hasAnnotation(serviceAnnos, EnableDatabaseMigration.class)) { + if (hasAnnotation(serviceClass.getAnnotations(), EnableDatabaseMigration.class)) { //this will block until the database is available. //it will then attempt a migration. if the migration fails, // the process emits an error and pauses. it's senseless to continue. @@ -127,6 +125,15 @@ private static void displayHelpAndExitIfNeeded(String[] args, AbstractService se } } + private static void verifyEnvironmentAndExitIfNeeded(AbstractService service) { + try { + service.verifyEnvironment(); + } catch (Exception e) { + logger.error("Error while verifying environment - {}", e.getMessage(), e); + System.exit(-1); + } + } + private static void verifyDefaultCharset() { String charset = Charset.defaultCharset().name(); logger.info("Found charset {}", charset);