def main(): logging.basicConfig(filename='ordered_startup.log', level=logging.DEBUG) log = logging.getLogger('ordered_startup_supervisord.main') try: config_file = None if len(sys.argv) > 1: config_file = sys.argv[1] if config_file is None: config_file = get_default_config_file() if config_file is None: print("Unable to find a config file!", file=sys.stderr) sys.exit(1) if not os.path.exists(config_file): print("Config path {} does not exist!".format(config_file), file=sys.stderr) sys.exit(1) parser = UnhosedConfigParser() parser.read(get_all_configs(config_file)) startup_plan = StartupPlan(parser) rpcinterface = childutils.getRPCInterface(os.environ) log.info("programs in order: ") for prog in startup_plan.programs: log.info(prog.name) if not startup_plan.programs[0].options.autostart: rpcinterface.supervisor.startProcess(startup_plan.programs[0].name, False) initial_start = 'STARTED' while 1: headers, payload = childutils.listener.wait() if headers['eventname'].startswith( 'PROCESS_STATE') and initial_start != 'FINISHED': pheaders = childutils.get_headers(payload) log.debug("headers = {}".format(repr(headers))) log.debug("payload = {}".format(repr(pheaders))) state = headers['eventname'][len('PROCESS_STATE_'):] start_next = False for program in startup_plan.programs: if start_next: log.info("Starting process: {}".format(program.name)) rpcinterface.supervisor.startProcess(program.name) start_next = False break if program.options.startinorder and program.name == pheaders[ 'processname'] and program.options.startnextafter == state: log.info( "Recieved process state of {} from {}, starting next process." .format(state, program.name)) start_next = True else: if start_next: log.info( "No more processes to start for initial startup, ignoring all future events." ) initial_start = 'FINISHED' #log.debug("data = {}".format(repr(pdata))) childutils.listener.ok() except: log.error("ERROR: ", exc_info=sys.exc_info())
def _make_config_parser(self, section_name, options): config_parser = UnhosedConfigParser() try: config_parser.add_section(section_name) for key, value in dict(options).items(): config_parser.set(section_name, key, value) except (TypeError, ValueError) as e: return RPCError(SupervisorFaults.INCORRECT_PARAMETERS) return config_parser
def _makeConfigParser(self, section_name, options): """ Populate a new UnhosedConfigParser instance with a section built from an options dict. """ config = UnhosedConfigParser() try: config.add_section(section_name) for k, v in dict(options).items(): config.set(section_name, k, v) except (TypeError, ValueError): raise RPCError(SupervisorFaults.INCORRECT_PARAMETERS) return config
def _makeConfigParser(self, section_name, options): config = UnhosedConfigParser() try: config.add_section(section_name) for k, v in dict(options).items(): config.set(section_name, k, v) except (TypeError, ValueError): raise RPCError(SupervisorFaults.INCORRECT_PARAMETERS) return config
def get_all_configs(root_path): """Get all the configuration files to be parsed. This is kinda weird because in order to do it we must parse the configs. """ retval = [root_path] parser = UnhosedConfigParser() parser.read(root_path) if 'include' in parser.sections() and parser.has_option('include', 'files'): files = parser.get('include', 'files').split() base_dir = os.path.dirname(os.path.abspath(root_path)) for pattern in files: if pattern.startswith('/'): for config in glob.glob(pattern): retval.extend(get_all_configs(config)) else: for config in glob.glob(os.path.join(base_dir, pattern)): retval.extend(get_all_configs(config)) return retval
def _make_config_parser(self, section_name, section_options): """ Populates a new UnhosedConfigParser instance with a section built from a dict of section options. Args: section_name (str) -- The name of the section section_options (dict) -- The configuration options for the section Returns: config (supervisor.options.UnhosedConfgParser) Raises: RPCError: Raises error if section parameters are invalid """ config = UnhosedConfigParser() try: config.add_section(section_name) for key, value in dict(section_options).items(): config.set(section_name, key, value) except (TypeError, ValueError): raise RPCError(Faults.INCORRECT_PARAMETERS) return config
def __init__(self, *args, **kwargs): self.common_expansions = kwargs.pop('common_expansions', None) UnhosedConfigParser.__init__(self, *args, **kwargs)