001package io.ebean.docker.container; 002 003import org.slf4j.Logger; 004import org.slf4j.LoggerFactory; 005 006import java.io.IOException; 007import java.io.InputStream; 008import java.util.Properties; 009 010/** 011 * Automatically start containers based on docker run properties file. 012 */ 013public class AutoStart { 014 015 private static Logger log = LoggerFactory.getLogger(AutoStart.class); 016 017 /** 018 * Search for docker-run.properties and start containers. 019 */ 020 public static void run() { 021 new AutoStart().run(loadProps()); 022 } 023 024 /** 025 * Search for docker-run.properties and stop all the containers. 026 */ 027 public static void stop() { 028 new AutoStart().stop(loadProps()); 029 } 030 031 private static Properties loadProps() { 032 Properties properties = new Properties(); 033 try (InputStream is = AutoStart.class.getResourceAsStream("/docker-run.properties")) { 034 if (is != null) { 035 properties.load(is); 036 } 037 } catch (IOException e) { 038 log.warn("failed to load docker-run.properties file", e); 039 } 040 return properties; 041 } 042 043 /** 044 * Start containers based on the given properties. 045 */ 046 private void run(Properties properties) { 047 new ContainerFactory(properties).startContainers(); 048 } 049 050 /** 051 * Start containers based on the given properties. 052 */ 053 private void stop(Properties properties) { 054 new ContainerFactory(properties).stopContainers(); 055 } 056}