Ensure that the named service is dead by stopping the service if it is running

    name
        The name of the init or rc script used to manage the service

    enable
        Set the service to be enabled at boot time, ``True`` sets the service
        to be enabled, ``False`` sets the named service to be disabled. The
        default is ``None``, which does not enable or disable anything.

    sig
        The string to search for when looking for the service process with ps

    init_delay
        Add a sleep command (in seconds) before the check to make sure service
        is killed.

        .. versionadded:: 2017.7.0

    no_block : False
        **For systemd minions only.** Stops the service using ``--no-block``.

        .. versionadded:: 2017.7.0

def dead(name,
         enable=None,
         sig=None,
         init_delay=None,
         **kwargs):
    '''
    Ensure that the named service is dead by stopping the service if it is running

    name
        The name of the init or rc script used to manage the service

    enable
        Set the service to be enabled at boot time, ``True`` sets the service
        to be enabled, ``False`` sets the named service to be disabled. The
        default is ``None``, which does not enable or disable anything.

    sig
        The string to search for when looking for the service process with ps

    init_delay
        Add a sleep command (in seconds) before the check to make sure service
        is killed.

        .. versionadded:: 2017.7.0

    no_block : False
        **For systemd minions only.** Stops the service using ``--no-block``.

        .. versionadded:: 2017.7.0
    '''
    ret = {'name': name,
           'changes': {},
           'result': True,
           'comment': ''}

    # Check for common error: using enabled option instead of enable
    if 'enabled' in kwargs:
        return _enabled_used_error(ret)

    # Convert enable to boolean in case user passed a string value
    if isinstance(enable, six.string_types):
        enable = salt.utils.data.is_true(enable)

    # Check if the service is available
    try:
        if not _available(name, ret):
            if __opts__.get('test'):
                ret['result'] = None
                ret['comment'] = 'Service {0} not present; if created in this state run, it would have been stopped'.format(name)
            else:
                # A non-available service is OK here, don't let the state fail
                # because of it.
                ret['result'] = True
            return ret
    except CommandExecutionError as exc:
        ret['result'] = False
        ret['comment'] = exc.strerror
        return ret

    # lot of custom init script won't or mis implement the status
    # command, so it is just an indicator but can not be fully trusted
    before_toggle_status = __salt__['service.status'](name, sig)
    if 'service.enabled' in __salt__:
        if salt.utils.platform.is_windows():
            # service.enabled in Windows returns True for services that are set
            # to Auto start, but services set to Manual can also be disabled
            before_toggle_enable_status = __salt__['service.info'](name)['StartType'] in ['Auto', 'Manual']
        else:
            before_toggle_enable_status = __salt__['service.enabled'](name)
    else:
        before_toggle_enable_status = True

    # See if the service is already dead
    if not before_toggle_status:
        ret['comment'] = 'The service {0} is already dead'.format(name)
        if enable is True and not before_toggle_enable_status:
            ret.update(_enable(name, None, skip_verify=False, **kwargs))
        elif enable is False and before_toggle_enable_status:
            ret.update(_disable(name, None, skip_verify=False, **kwargs))
        return ret

    # Run the tests
    if __opts__['test']:
        ret['result'] = None
        ret['comment'] = 'Service {0} is set to be killed'.format(name)
        return ret

    # Conditionally add systemd-specific args to call to service.start
    stop_kwargs, warnings = _get_systemd_only(__salt__['service.stop'], kwargs)
    if warnings:
        ret.setdefault('warnings', []).extend(warnings)

    if salt.utils.platform.is_windows():
        for arg in ['timeout', 'with_deps', 'with_parents']:
            if kwargs.get(arg, False):
                stop_kwargs.update({arg: kwargs.get(arg)})

    func_ret = __salt__['service.stop'](name, **stop_kwargs)
    if not func_ret:
        ret['result'] = False
        ret['comment'] = 'Service {0} failed to die'.format(name)
        if enable is True:
            ret.update(_enable(name, True, result=False, skip_verify=False, **kwargs))
        elif enable is False:
            ret.update(_disable(name, True, result=False, skip_verify=False, **kwargs))
        return ret

    if init_delay:
        time.sleep(init_delay)

    # only force a change state if we have explicitly detected them
    after_toggle_status = __salt__['service.status'](name)
    if 'service.enabled' in __salt__:
        after_toggle_enable_status = __salt__['service.enabled'](name)
    else:
        after_toggle_enable_status = True
    if (
            (before_toggle_enable_status != after_toggle_enable_status) or
            (before_toggle_status != after_toggle_status)
    ) and not ret.get('changes', {}):
        ret['changes'][name] = after_toggle_status

    # be sure to stop, in case we mis detected in the check
    if after_toggle_status:
        ret['result'] = False
        ret['comment'] = 'Service {0} failed to die'.format(name)
    else:
        ret['comment'] = 'Service {0} was killed'.format(name)

    if enable is True:
        ret.update(_enable(name, after_toggle_status, result=not after_toggle_status, skip_verify=False, **kwargs))
    elif enable is False:
        ret.update(_disable(name, after_toggle_status, result=not after_toggle_status, skip_verify=False, **kwargs))

    return ret