Esempio n. 1
0
def safe_reboot():
    """Reboot a mongo machine, stepping down if it is the primary"""
    import vm
    if not vm.reboot_required():
        print("No reboot required")
        return

    while True:
        if cluster_is_ok():
            break
        sleep(5)
        print("Waiting for cluster to be okay")

    primary = _find_primary()
    if primary == 'No primary currently elected':
        return primary

    if i_am_primary(primary):
        execute(step_down_primary)

    for i in range(5):
        if cluster_is_ok() and not i_am_primary():
            break
        sleep(1)

    if not cluster_is_ok() or i_am_primary():
        abort("Cluster has not recovered")

    execute(vm.reboot, hosts=[env['host_string']])
Esempio n. 2
0
def safe_reboot():
    """Reboot only if the cluster is currently green"""
    import vm
    if not vm.reboot_required():
        print("No reboot required")
        return

    wait_for_status("green")
    disable_reallocation()

    try:
        execute(vm.reboot, hosts=[env['host_string']])

        # Give the reboot time to start, before we check for the status again.
        sleep(10)

        # Status won't usually go back to green while reallocation is turned
        # off, but should go to yellow.
        wait_for_status("green", "yellow")
        enable_reallocation()
    except:
        print(
            "Failed to re-enable allocation - "
            "you will need to enable it again using the "
            "'elasticsearch.enable_reallocation' fabric command"
        )
        raise
Esempio n. 3
0
def safe_reboot():
    """Reboot only if the cluster is currently green"""
    import vm
    if not vm.reboot_required():
        print("No reboot required")
        return

    wait_for_status("green")
    disable_reallocation()

    try:
        execute(vm.reboot, hosts=[env['host_string']])

        # Give the reboot time to start, before we check for the status again.
        sleep(10)

        # Status won't usually go back to green while reallocation is turned
        # off, but should go to yellow.
        wait_for_status("green", "yellow")
        enable_reallocation()
    except:
        print("Failed to re-enable allocation - "
              "you will need to enable it again using the "
              "'elasticsearch.enable_reallocation' fabric command")
        raise
Esempio n. 4
0
def safe_reboot():
    """Reboot a mongo machine, stepping down if it is the primary"""
    import vm
    if not vm.reboot_required():
        print("No reboot required")
        return

    while True:
        if cluster_is_ok():
            break
        sleep(5)
        print("Waiting for cluster to be okay")

    primary = _find_primary()
    if primary == 'No primary currently elected':
        return primary

    if i_am_primary(primary):
        execute(step_down_primary)

    for i in range(10):
        if cluster_is_ok() and not i_am_primary():
            break
        sleep(1)

    if not cluster_is_ok() or i_am_primary():
        abort("Cluster has not recovered")

    execute(vm.reboot, hosts=[env['host_string']])
def safe_reboot():
    """Reboot a mongo machine, stepping down if it is the primary"""
    import vm
    if not vm.reboot_required():
        print("No reboot required")
        return

    with hide("everything"):
        _wait_for_ok()

    if _i_am_primary():
        execute(step_down_primary)

    with hide("everything"):
        _wait_for_ok()

    execute(vm.reboot, hosts=[env['host_string']])