in twill-yarn/src/main/java/org/apache/twill/internal/ServiceMain.java [74:123]
protected final void doMain(final Service mainService,
Service...prerequisites) throws ExecutionException, InterruptedException {
configureLogger();
Service requiredServices = new CompositeService(prerequisites);
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
mainService.stopAndWait();
}
});
// Listener for state changes of the service
ListenableFuture<Service.State> completion = Services.getCompletionFuture(mainService);
Throwable initFailure = null;
try {
try {
// Starts the service
LOG.info("Starting service {}.", mainService);
Futures.allAsList(Services.chainStart(requiredServices, mainService).get()).get();
LOG.info("Service {} started.", mainService);
} catch (Throwable t) {
LOG.error("Exception when starting service {}.", mainService, t);
initFailure = t;
}
try {
if (initFailure == null) {
completion.get();
LOG.info("Service {} completed.", mainService);
}
} catch (Throwable t) {
LOG.error("Exception thrown from service {}.", mainService, t);
throw Throwables.propagate(t);
}
} finally {
requiredServices.stopAndWait();
ILoggerFactory loggerFactory = LoggerFactory.getILoggerFactory();
if (loggerFactory instanceof LoggerContext) {
((LoggerContext) loggerFactory).stop();
}
if (initFailure != null) {
// Exit with the init fail exit code.
System.exit(ContainerExitCodes.INIT_FAILED);
}
}
}