コード例 #1
0
    def run(self, id, updated_fields):
        service_def = self.datastore.get_by_id('service_definitions', id)
        node = ConfigNode('service.{0}'.format(service_def['name']), self.configstore)
        restart = False
        reload = False
        updated_config = updated_fields.get('config')

        if updated_config is None:
            return

        del updated_config['type']

        if service_def.get('task'):
            enable = updated_config.pop('enable', None)

            try:
                self.verify_subtask(service_def['task'], updated_config)
            except RpcException as err:
                new_err = ValidationException()
                new_err.propagate(err, [0], [1, 'config'])
                raise new_err

            result = self.join_subtasks(self.run_subtask(service_def['task'], updated_config))
            restart = result[0] == 'RESTART'
            reload = result[0] == 'RELOAD'

            if enable is not None:
                node['enable'] = enable
        else:
            node.update(updated_config)

            if service_def.get('etcd-group'):
                self.dispatcher.call_sync('etcd.generation.generate_group', service_def.get('etcd-group'))

            if 'enable' in updated_config:
                # Propagate to dependent services
                for i in service_def.get('dependencies', []):
                    svc_dep = self.datastore.get_by_id('service_definitions', i)
                    self.join_subtasks(self.run_subtask('service.update', i, {
                        'config': {
                            'type': 'service-{0}'.format(svc_dep['name']),
                            'enable': updated_config['enable']
                        }
                    }))

                if service_def.get('auto_enable'):
                    # Consult state of services dependent on us
                    for i in self.datastore.query('service_definitions', ('dependencies', 'in', service_def['name'])):
                        enb = self.configstore.get('service.{0}.enable', i['name'])
                        if enb != updated_config['enable']:
                            del updated_config['enable']
                            break

        self.dispatcher.call_sync('etcd.generation.generate_group', 'services')
        self.dispatcher.call_sync('service.apply_state', service_def['name'], restart, reload, timeout=30)
        self.dispatcher.dispatch_event('service.changed', {
            'operation': 'update',
            'ids': [service_def['id']]
        })
コード例 #2
0
    def run(self, id, updated_fields):
        service_def = self.datastore.get_by_id('service_definitions', id)
        if not service_def:
            raise TaskException(errno.ENOENT,
                                'Service {0} not found'.format(id))

        if 'config' in updated_fields:
            for x in updated_fields['config']:
                if x == 'type':
                    continue

                if not self.configstore.exists('service.{0}.{1}'.format(
                        service_def['name'], x)):
                    raise TaskException(
                        errno.ENOENT,
                        'Service {0} does not have the following key: {1}'.
                        format(service_def['name'], x))

        node = ConfigNode('service.{0}'.format(service_def['name']),
                          self.configstore)
        restart = False
        reload = False
        updated_config = updated_fields.get('config')
        if updated_config is None:
            return

        enable = not node['enable'].value and updated_config['enable']
        disable = node['enable'].value and not updated_config['enable']
        updated_config.pop('type', None)

        if service_def.get('task'):
            try:
                self.verify_subtask(service_def['task'], updated_config)
            except RpcException as err:
                new_err = ValidationException()
                new_err.propagate(err, [0], [1, 'config'])
                raise new_err

            result = self.run_subtask_sync(service_def['task'],
                                           updated_config,
                                           progress_callback=self.set_progress)

            restart = result == 'RESTART'
            reload = result == 'RELOAD'

            if updated_config.get('enable') is not None:
                node['enable'] = updated_config['enable']
        else:
            node.update(updated_config)

            if service_def.get('etcd-group'):
                self.dispatcher.call_sync('etcd.generation.generate_group',
                                          service_def.get('etcd-group'))

        if 'enable' in updated_config:
            # Propagate to dependent services
            for i in service_def.get('dependencies', []):
                svc_dep = self.datastore.get_by_id('service_definitions', i)
                self.run_subtask_sync(
                    'service.update', i, {
                        'config': {
                            'type': 'service-{0}'.format(svc_dep['name']),
                            'enable': updated_config['enable']
                        }
                    })

            if service_def.get('auto_enable'):
                # Consult state of services dependent on us
                for i in self.datastore.query(
                        'service_definitions',
                    ('dependencies', 'in', service_def['name'])):
                    enb = self.configstore.get('service.{0}.enable', i['name'])
                    if enb != updated_config['enable']:
                        del updated_config['enable']
                        break

        if 'launchd' in service_def:
            if enable:
                load_job(self.dispatcher, service_def)

            if disable:
                unload_job(self.dispatcher, service_def)

        self.dispatcher.call_sync('etcd.generation.generate_group', 'services')
        self.dispatcher.call_sync('service.apply_state',
                                  service_def['name'],
                                  restart,
                                  reload,
                                  timeout=120)
        self.dispatcher.dispatch_event('service.changed', {
            'operation': 'update',
            'ids': [service_def['id']]
        })
コード例 #3
0
    def run(self, id, updated_fields):
        service_def = self.datastore.get_by_id('service_definitions', id)
        if not service_def:
            raise TaskException(
                errno.ENOENT,
                'Service {0} not found'.format(id)
            )

        if 'config' in updated_fields:
            for x in updated_fields['config']:
                if x == 'type':
                    continue

                if not self.configstore.exists('service.{0}.{1}'.format(service_def['name'], x)):
                    raise TaskException(
                        errno.ENOENT,
                        'Service {0} does not have the following key: {1}'.format(
                            service_def['name'], x))

        node = ConfigNode('service.{0}'.format(service_def['name']), self.configstore)
        restart = False
        reload = False
        updated_config = updated_fields.get('config')
        if updated_config is None:
            return

        enable = not node['enable'].value and updated_config['enable']
        disable = node['enable'].value and not updated_config['enable']
        updated_config.pop('type', None)

        if service_def.get('task'):
            try:
                self.verify_subtask(service_def['task'], updated_config)
            except RpcException as err:
                new_err = ValidationException()
                new_err.propagate(err, [0], [1, 'config'])
                raise new_err

            result = self.run_subtask_sync(service_def['task'], updated_config)
            restart = result == 'RESTART'
            reload = result == 'RELOAD'

            if updated_config.get('enable') is not None:
                node['enable'] = updated_config['enable']
        else:
            node.update(updated_config)

            if service_def.get('etcd-group'):
                self.dispatcher.call_sync('etcd.generation.generate_group', service_def.get('etcd-group'))

            if 'enable' in updated_config:
                # Propagate to dependent services
                for i in service_def.get('dependencies', []):
                    svc_dep = self.datastore.get_by_id('service_definitions', i)
                    self.run_subtask_sync('service.update', i, {
                        'config': {
                            'type': 'service-{0}'.format(svc_dep['name']),
                            'enable': updated_config['enable']
                        }
                    })

                if service_def.get('auto_enable'):
                    # Consult state of services dependent on us
                    for i in self.datastore.query('service_definitions', ('dependencies', 'in', service_def['name'])):
                        enb = self.configstore.get('service.{0}.enable', i['name'])
                        if enb != updated_config['enable']:
                            del updated_config['enable']
                            break

        if 'launchd' in service_def:
            if enable:
                load_job(self.dispatcher, service_def)

            if disable:
                unload_job(self.dispatcher, service_def)

        self.dispatcher.call_sync('etcd.generation.generate_group', 'services')
        self.dispatcher.call_sync('service.apply_state', service_def['name'], restart, reload, timeout=120)
        self.dispatcher.dispatch_event('service.changed', {
            'operation': 'update',
            'ids': [service_def['id']]
        })