Skip to content
This repository was archived by the owner on Jan 30, 2020. It is now read-only.

Exit application if environment verification failed #75

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/main/java/com/sixt/service/framework/JettyServiceBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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);
Expand Down