Beispiel #1
0
def update_job(name, config):
    '''
    Update the specified job with the given configuration.

    CLI Example:

    .. code-block:: bash

        salt chronos-minion-id chronos.update_job my-job '<config yaml>'
    '''
    if 'name' not in config:
        config['name'] = name
    data = json.dumps(config)
    try:
        response = salt.utils.http.query(
            "{0}/scheduler/iso8601".format(_base_url()),
            method='POST',
            data=data,
            header_dict={
                'Content-Type': 'application/json',
            },
        )
        log.debug('update response: %s', response)
        return {'success': True}
    except Exception as ex:
        log.error('unable to update chronos job: %s', get_error_message(ex))
        return {
            'exception': {
                'message': get_error_message(ex),
            }
        }
Beispiel #2
0
    def environment_failure(self, error):
        '''
        Log environment failure for the daemon and exit with the error code.

        :param error:
        :return:
        '''
        log.exception('Failed to create environment for {d_name}: {reason}'.format(
            d_name=self.__class__.__name__, reason=get_error_message(error)))
        self.shutdown(error)
Beispiel #3
0
def update_app(id, config):
    '''
    Update the specified app with the given configuration.

    CLI Example:

    .. code-block:: bash

        salt marathon-minion-id marathon.update_app my-app '<config yaml>'
    '''
    if 'id' not in config:
        config['id'] = id
    config.pop('version', None)
    # mirror marathon-ui handling for uris deprecation (see
    # mesosphere/marathon-ui#594 for more details)
    config.pop('fetch', None)
    data = salt.utils.json.dumps(config)
    try:
        response = salt.utils.http.query(
            "{0}/v2/apps/{1}?force=true".format(_base_url(), id),
            method='PUT',
            decode_type='json',
            decode=True,
            data=data,
            header_dict={
                'Content-Type': 'application/json',
                'Accept': 'application/json',
            },
        )
        log.debug('update response: %s', response)
        return response['dict']
    except Exception as ex:  # pylint: disable=broad-except
        log.error('unable to update marathon app: %s', get_error_message(ex))
        return {
            'exception': {
                'message': get_error_message(ex),
            }
        }
Beispiel #4
0
def update_app(id, config):
    '''
    Update the specified app with the given configuration.

    CLI Example:

    .. code-block:: bash

        salt marathon-minion-id marathon.update_app my-app '<config yaml>'
    '''
    if 'id' not in config:
        config['id'] = id
    config.pop('version', None)
    # mirror marathon-ui handling for uris deprecation (see
    # mesosphere/marathon-ui#594 for more details)
    config.pop('fetch', None)
    data = json.dumps(config)
    try:
        response = salt.utils.http.query(
            "{0}/v2/apps/{1}?force=true".format(_base_url(), id),
            method='PUT',
            decode_type='json',
            decode=True,
            data=data,
            header_dict={
                'Content-Type': 'application/json',
                'Accept': 'application/json',
            },
        )
        log.debug('update response: %s', response)
        return response['dict']
    except Exception as ex:
        log.error('unable to update marathon app: %s', get_error_message(ex))
        return {
            'exception': {
                'message': get_error_message(ex),
            }
        }
Beispiel #5
0
def minion_process(queue):
    '''
    Start a minion process
    '''
    import salt.cli.daemons

    # salt_minion spawns this function in a new process

    def suicide_when_without_parent(parent_pid):
        '''
        Have the minion suicide if the parent process is gone

        NOTE: there is a small race issue where the parent PID could be replace
        with another process with the same PID!
        '''
        while True:
            time.sleep(5)
            try:
                # check pid alive (Unix only trick!)
                if os.getuid() == 0 and not salt.utils.is_windows():
                    os.kill(parent_pid, 0)
            except OSError as exc:
                # forcibly exit, regular sys.exit raises an exception-- which
                # isn't sufficient in a thread
                log.error(
                    'Minion process encountered exception: {0}'.format(exc))
                os._exit(999)

    if not salt.utils.is_windows():
        thread = threading.Thread(target=suicide_when_without_parent,
                                  args=(os.getppid(), ))
        thread.start()

    restart = False
    minion = None
    try:
        minion = salt.cli.daemons.Minion()
        minion.start()
    except ImportError as exc:
        log.error(exc)
    except (Exception, SaltClientError, SaltReqTimeoutError,
            SaltSystemExit) as exc:
        log.error('Minion failed to start: {0}'.format(get_error_message(exc)),
                  exc_info=True)
        restart = True
    except SystemExit as exc:
        log.error(exc)

    if restart is True:
        log.warning('Fatal functionality error caught by minion handler:\n',
                    exc_info=True)
        log.warn('** Restarting minion **')
        delay = 60
        if minion is not None:
            if hasattr(minion, 'config'):
                delay = minion.config.get('random_reauth_delay', 60)
        random_delay = randint(1, delay)
        log.info(
            'Sleeping random_reauth_delay of {0} seconds'.format(random_delay))
        # preform delay after minion resources have been cleaned
        if minion.options.daemon:
            time.sleep(random_delay)
            salt_minion()
        else:
            queue.put(random_delay)
    else:
        queue.put(0)