def register_service_in_service_registry(service, capabilities=None, start_heart=True):
    """
    Register provided service in the service registry and start the heartbeat process.

    :param service: Service name which will also be used for a group name (e.g. "api").
    :type service: ``str``

    :param capabilities: Optional metadata associated with the service.
    :type capabilities: ``dict``
    """
    # NOTE: It's important that we pass start_heart=True to start the hearbeat process
    coordinator = coordination.get_coordinator(start_heart=start_heart)

    member_id = coordination.get_member_id()

    # 1. Create a group with the name of the service
    if not isinstance(service, six.binary_type):
        group_id = service.encode("utf-8")
    else:
        group_id = service

    try:
        coordinator.create_group(group_id).get()
    except GroupAlreadyExist:
        pass

    # Include common capabilities such as hostname and process ID
    proc_info = system_info.get_process_info()
    capabilities["hostname"] = proc_info["hostname"]
    capabilities["pid"] = proc_info["pid"]

    # 1. Join the group as a member
    LOG.debug(
        'Joining service registry group "%s" as member_id "%s" with capabilities "%s"'
        % (group_id, member_id, capabilities)
    )
    return coordinator.join_group(group_id, capabilities=capabilities).get()

    Register provided service in the service registry and start the heartbeat process.

    :param service: Service name which will also be used for a group name (e.g. "api").
    :type service: ``str``

    :param capabilities: Optional metadata associated with the service.
    :type capabilities: ``dict``
    
st2common/st2common/service_setup.py