示例#1
0
 def server_configs_from_parser(self, parser):
     """ The following has nothing to deal with Supervisor's server configurations.
     It gets Supvisors configuration.
     Supervisor's ServerOptions has not been designed to be specialized.
     This method is overriden just to have an access point to the Supervisor parser. """
     configs = ServerOptions.server_configs_from_parser(self, parser)
     # set section
     if not parser.has_section(SupvisorsServerOptions._Section):
         raise ValueError('.ini file ({}) does not include a [{}] section'.format(self.configfile, self._Section))
     temp, parser.mysection = parser.mysection, self._Section
     # get values
     opt = self.supvisors_options
     opt.address_list = list(OrderedDict.fromkeys(filter(None, list_of_strings(parser.getdefault('address_list', gethostname())))))
     opt.rules_file = parser.getdefault('rules_file', None)
     if opt.rules_file:
         opt.rules_file = existing_dirpath(opt.rules_file)
     opt.internal_port = self.to_port_num(parser.getdefault('internal_port', '65001'))
     opt.event_port = self.to_port_num(parser.getdefault('event_port', '65002'))
     opt.auto_fence = boolean(parser.getdefault('auto_fence', 'false'))
     opt.synchro_timeout = self.to_timeout(parser.getdefault('synchro_timeout', '15'))
     opt.conciliation_strategy = self.to_conciliation_strategy(parser.getdefault('conciliation_strategy', 'USER'))
     opt.starting_strategy = self.to_starting_strategy(parser.getdefault('starting_strategy', 'CONFIG'))
     # configure statistics
     opt.stats_periods = self.to_periods(list_of_strings(parser.getdefault('stats_periods', '10')))
     opt.stats_histo = self.to_histo(parser.getdefault('stats_histo', 200))
     opt.stats_irix_mode = boolean(parser.getdefault('stats_irix_mode', 'false'))
     # configure logger
     opt.logfile = existing_dirpath(parser.getdefault('logfile', '{}.log'.format(SupvisorsServerOptions._Section)))
     opt.logfile_maxbytes = byte_size(parser.getdefault('logfile_maxbytes', '50MB'))
     opt.logfile_backups = integer(parser.getdefault('logfile_backups', 10))
     opt.loglevel = logging_level(parser.getdefault('loglevel', 'info'))
     # reset mysection and return original result
     parser.mysection = temp
     return configs
示例#2
0
 def _processes_from_section(self, parser, section, group_name, klass=None):
     """ This method is overriden to store the program number of a homogeneous program.
     This is used in Supervisor to set the real program name from the format defined in the ini file.
     However, Supervisor does not keep this information in its internal structure. """
     # call super behaviour
     programs = ServerOptions._processes_from_section(self, parser, section, group_name, klass)
     # store the number of each program
     for idx, program in enumerate(programs):
         self.supvisors_options.procnumbers[program.name] = idx
     # return original result
     return programs
示例#3
0
 def _processes_from_section(self, parser, section, group_name, klass=None):
     """ This method is overriden to store the program number of a homogeneous program.
     This is used in Supervisor to set the real program name from the format defined in the ini file.
     However, Supervisor does not keep this information in its internal structure. """
     # call super behaviour
     programs = ServerOptions._processes_from_section(
         self, parser, section, group_name, klass)
     # store the number of each program
     for idx, program in enumerate(programs):
         self.supvisors_options.procnumbers[program.name] = idx
     # return original result
     return programs
示例#4
0
def main(args=None, test=False):
    # assert os.name == "posix", "This code makes Unix-specific assumptions"
    # if we hup, restart by making a new Supervisor()
    first = True
    while 1:
        options = ServerOptions()
        options.realize(args, doc=__doc__)
        options.first = first
        options.test = test
        try:
            if options.profile_options:
                sort_order, callers = options.profile_options
                profile('go(options)', globals(), locals(), sort_order,
                        callers)
            else:
                go(options)
        finally:
            options.close_httpservers()
            options.close_logger()
        first = False
        if test or (options.mood < SupervisorStates.RESTARTING):
            break
示例#5
0
 def server_configs_from_parser(self, parser):
     """ The following has nothing to deal with Supervisor's server configurations.
     It gets Supvisors configuration.
     Supervisor's ServerOptions has not been designed to be specialized.
     This method is overriden just to have an access point to the Supervisor parser. """
     configs = ServerOptions.server_configs_from_parser(self, parser)
     # set section
     if not parser.has_section(SupvisorsServerOptions._Section):
         raise ValueError(
             '.ini file ({}) does not include a [{}] section'.format(
                 self.configfile, self._Section))
     temp, parser.mysection = parser.mysection, self._Section
     # get values
     opt = self.supvisors_options
     opt.address_list = list(
         OrderedDict.fromkeys(
             filter(
                 None,
                 list_of_strings(
                     parser.getdefault('address_list', gethostname())))))
     opt.deployment_file = parser.getdefault('deployment_file', None)
     if opt.deployment_file:
         opt.deployment_file = existing_dirpath(opt.deployment_file)
     opt.internal_port = self.to_port_num(
         parser.getdefault('internal_port', '65001'))
     opt.event_port = self.to_port_num(
         parser.getdefault('event_port', '65002'))
     opt.auto_fence = boolean(parser.getdefault('auto_fence', 'false'))
     opt.synchro_timeout = self.to_timeout(
         parser.getdefault('synchro_timeout', '15'))
     opt.conciliation_strategy = self.to_conciliation_strategy(
         parser.getdefault('conciliation_strategy', 'USER'))
     opt.deployment_strategy = self.to_deployment_strategy(
         parser.getdefault('deployment_strategy', 'CONFIG'))
     # configure statistics
     opt.stats_periods = self.to_periods(
         list_of_strings(parser.getdefault('stats_periods', '10')))
     opt.stats_histo = self.to_histo(parser.getdefault('stats_histo', 200))
     opt.stats_irix_mode = boolean(
         parser.getdefault('stats_irix_mode', 'false'))
     # configure logger
     opt.logfile = existing_dirpath(
         parser.getdefault('logfile', '{}.log'.format(
             SupvisorsServerOptions._Section)))
     opt.logfile_maxbytes = byte_size(
         parser.getdefault('logfile_maxbytes', '50MB'))
     opt.logfile_backups = integer(parser.getdefault('logfile_backups', 10))
     opt.loglevel = logging_level(parser.getdefault('loglevel', 'info'))
     # reset mysection and return original result
     parser.mysection = temp
     return configs
示例#6
0
def main(args=None, test=False):
    assert os.name == "posix", "This code makes Unix-specific assumptions"
    # if we hup, restart by making a new Supervisor()
    first = True
    while 1:
        options = ServerOptions()
        options.realize(args, doc=__doc__)
        options.first = first
        options.test = test
        if options.profile_options:
            sort_order, callers = options.profile_options
            profile('go(options)', globals(), locals(), sort_order, callers)
        else:
            go(options)
        if test or (options.mood < SupervisorStates.RESTARTING):
            break
        options.close_httpservers()
        options.close_logger()
        first = False
def main(args=None, test=False):
    assert os.name == "posix", "This code makes Unix-specific assumptions"
    # if we hup, restart by making a new Supervisor()
    first = True
    # while 1:
    if 1:
        options = ServerOptions()
        # attribute_value = options.__dict__
        # for key,value in attribute_value.items():
        #     print(key,value)
        # __doc__ 该文件下
        options.realize(args, doc=__doc__)
        options.first = first
        options.test = test

        if options.profile_options:
            sort_order, callers = options.profile_options
            profile('go(options)', globals(), locals(), sort_order, callers)
        else:
            go(options)
        options.close_httpservers()
        options.close_logger()
        first = False
示例#8
0
def main():
    module = AnsibleModule(
        argument_spec = dict(
            config=dict(required=True, type='path'),
            state=dict(default='present', choices=['present', 'absent'])
        ),
        supports_check_mode=True
    )

    configfile = module.params['config']

    options = ServerOptions()
    options.configfile = configfile
    options.progname = 'supervisord'

    try:
        options.process_config(do_usage=True)
    except ValueError as e:
        module.fail_json(msg = e.message.message)

    options.realize(args=[], progname='supervisord')

    server = xmlrpclib.ServerProxy(
        'http://127.0.0.1',
        allow_none=True,
        transport=SupervisorTransport(serverurl=options.serverurl))

    try:
        server.supervisor.getPID()
        state = 'present'
    except socket.error:
        state = 'absent'

    desired = module.params['state']

    if state == desired:
        module.exit_json(changed=False)

    if not module.check_mode:
        if desired == 'present':
            module.run_command(["supervisord", "-c", configfile], check_rc=True)
        elif desired == 'absent':
            server.supervisor.shutdown()

    module.exit_json(changed=True)
示例#9
0
 def __init__(self):
     """ Initialization of the attributes. """
     ServerOptions.__init__(self)
     self.supvisors_options = SupvisorsOptions()
示例#10
0
 def __init__(self):
     """ Initialization of the attributes. """
     ServerOptions.__init__(self)
     self.supvisors_options = SupvisorsOptions()
示例#11
0
 def __init__(self):
     """ Initialization of the attributes. 
     Default parameters fit, so realize is called directly. """
     ServerOptions.__init__(self)
     self.supvisors_options = SupvisorsOptions()