예제 #1
0
파일: stop.py 프로젝트: satybald/mongoctl
def kill_stop_server(server, pid):
    if pid is None:
        log_error(
            "Cannot forcibly stop the server because the server's process"
            " ID cannot be determined; pid file '%s' does not exist." %
            server.get_pid_file_path())
        return False

    log_info("Forcibly stopping server '%s'...\n" % server.id)
    log_info("Sending kill -1 (HUP) signal to server '%s' (pid=%s)..." %
             (server.id, pid))

    kill_process(pid, force=False)

    log_info("Will now wait for server '%s' (pid=%s) to die." %
             (server.id, pid))
    wait_for(pid_dead_predicate(pid), timeout=MAX_SHUTDOWN_WAIT)

    if is_pid_alive(pid):
        log_error("Failed to kill server process with -1 (HUP).")
        log_info("Sending kill -9 (SIGKILL) signal to server"
                 "'%s' (pid=%s)..." % (server.id, pid))
        kill_process(pid, force=True)

        log_info("Will now wait for server '%s' (pid=%s) to die." %
                 (server.id, pid))
        wait_for(pid_dead_predicate(pid), timeout=MAX_SHUTDOWN_WAIT)

    if not is_pid_alive(pid):
        log_info("Forcefully-stopped server '%s'." % server.id)
        return True
    else:
        log_error("Forceful stop of server '%s' failed." % server.id)
        return False
예제 #2
0
def kill_stop_server(server, pid):
    if pid is None:
        log_error("Cannot forcibly stop the server because the server's process"
                  " ID cannot be determined; pid file '%s' does not exist." %
                  server.get_pid_file_path())
        return False

    log_info("Forcibly stopping server '%s'...\n" % server.id)
    log_info("Sending kill -1 (HUP) signal to server '%s' (pid=%s)..." %
             (server.id, pid))

    kill_process(pid, force=False)

    log_info("Will now wait for server '%s' (pid=%s) to die." %
             (server.id, pid))
    wait_for(pid_dead_predicate(pid), timeout=MAX_SHUTDOWN_WAIT)

    if is_pid_alive(pid):
        log_error("Failed to kill server process with -1 (HUP).")
        log_info("Sending kill -9 (SIGKILL) signal to server"
                 "'%s' (pid=%s)..." % (server.id, pid))
        kill_process(pid, force=True)

        log_info("Will now wait for server '%s' (pid=%s) to die." %
                 (server.id, pid))
        wait_for(pid_dead_predicate(pid), timeout=MAX_SHUTDOWN_WAIT)

    if not is_pid_alive(pid):
        log_info("Forcefully-stopped server '%s'." % server.id)
        return True
    else:
        log_error("Forceful stop of server '%s' failed." % server.id)
        return False
예제 #3
0
def maybe_config_server_repl_set(server, rs_add=False, no_init=False):
    # if the server belongs to a replica set cluster,
    # then prompt the user to init the replica set IF not already initialized
    # AND server is NOT an Arbiter
    # OTHERWISE prompt to add server to replica if server is not added yet

    cluster = server.get_replicaset_cluster()

    if cluster is not None:
        log_verbose("Server '%s' is a member in the configuration for"
                    " cluster '%s'." % (server.id,cluster.id))

        if not cluster.is_replicaset_initialized():
            log_info("Replica set cluster '%s' has not been initialized yet." %
                     cluster.id)
            if cluster.get_member_for(server).can_become_primary():
                if not no_init:
                    if rs_add:
                        cluster.initialize_replicaset(server)
                    else:
                        prompt_init_replica_cluster(cluster, server)
                else:
                    log_warning("Replicaset is not initialized and you "
                                "specified --rs-add-nonit. Not adding to "
                                "replicaset...")
            else:
                log_info("Skipping replica set initialization because "
                         "server '%s' cannot be elected primary." %
                         server.id)
        else:
            log_verbose("No need to initialize cluster '%s', as it has"
                        " already been initialized." % cluster.id)
            if not cluster.is_member_configured_for(server):
                if server.has_joined_replica():
                    ## wait for server to finish joining replica
                    log_info("Waiting for server to finish joining replica set...")
                    wait_for(lambda: cluster.is_member_configured_for(server), timeout=10*60)

                elif rs_add:
                    cluster.add_member_to_replica(server)
                else:
                    prompt_add_member_to_replica(cluster, server)
            else:
                log_verbose("Server '%s' is already added to the replicaset"
                            " conf of cluster '%s'." %
                            (server.id, cluster.id))
예제 #4
0
def maybe_config_server_repl_set(server, rs_add=False, no_init=False):
    # if the server belongs to a replica set cluster,
    # then prompt the user to init the replica set IF not already initialized
    # AND server is NOT an Arbiter
    # OTHERWISE prompt to add server to replica if server is not added yet

    cluster = server.get_replicaset_cluster()

    if cluster is not None:
        log_verbose("Server '%s' is a member in the configuration for"
                    " cluster '%s'." % (server.id, cluster.id))

        if not cluster.is_replicaset_initialized():
            log_info("Replica set cluster '%s' has not been initialized yet." %
                     cluster.id)
            if cluster.get_member_for(server).can_become_primary():
                if not no_init:
                    if rs_add:
                        cluster.initialize_replicaset(server)
                    else:
                        prompt_init_replica_cluster(cluster, server)
                else:
                    log_warning("Replicaset is not initialized and you "
                                "specified --rs-add-nonit. Not adding to "
                                "replicaset...")
            else:
                log_info("Skipping replica set initialization because "
                         "server '%s' cannot be elected primary." % server.id)
        else:
            log_verbose("No need to initialize cluster '%s', as it has"
                        " already been initialized." % cluster.id)
            if not cluster.is_member_configured_for(server):
                if server.has_joined_replica():
                    ## wait for server to finish joining replica
                    log_info(
                        "Waiting for server to finish joining replica set...")
                    wait_for(lambda: cluster.is_member_configured_for(server),
                             timeout=10 * 60)

                elif rs_add:
                    cluster.add_member_to_replica(server)
                else:
                    prompt_add_member_to_replica(cluster, server)
            else:
                log_verbose("Server '%s' is already added to the replicaset"
                            " conf of cluster '%s'." % (server.id, cluster.id))
예제 #5
0
def mongo_stop_server(server, pid, force=False):
    try:
        shutdown_cmd = SON([('shutdown', 1), ('force', force)])
        log_info("\nSending the following command to %s:\n%s\n" %
                 (server.get_connection_address(),
                  document_pretty_string(shutdown_cmd)))
        server.disconnecting_db_command(shutdown_cmd, "admin")

        log_info("Will now wait for server '%s' to stop." % server.id)
        # Check that the server has stopped
        stop_pred = server_stopped_predicate(server, pid)
        wait_for(stop_pred, timeout=MAX_SHUTDOWN_WAIT)

        if not stop_pred():
            log_error("Shutdown command failed...")
            return False
        else:
            return True
    except Exception, e:
        log_exception(e)
        log_error("Failed to gracefully stop server '%s'. Cause: %s" %
                  (server.id, e))
        return False
예제 #6
0
파일: stop.py 프로젝트: sfdcmahi/mongoctl
def mongo_stop_server(server, pid, force=False):

    try:
        shutdown_cmd = SON([('shutdown', 1), ('force', force)])
        log_info("\nSending the following command to %s:\n%s\n" %
                 (server.get_connection_address(),
                  document_pretty_string(shutdown_cmd)))
        server.disconnecting_db_command(shutdown_cmd, "admin")

        log_info("Will now wait for server '%s' to stop." % server.id)
        # Check that the server has stopped
        stop_pred = server_stopped_predicate(server, pid)
        wait_for(stop_pred, timeout=MAX_SHUTDOWN_WAIT)

        if not stop_pred():
            log_error("Shutdown command failed...")
            return False
        else:
            return True
    except Exception, e:
        log_exception(e)
        log_error("Failed to gracefully stop server '%s'. Cause: %s" %
                  (server.id, e))
        return False
예제 #7
0
def start_server_process(server, options_override=None, standalone=False):

    set_server_executable_env_vars(server)
    mongod_pid = _start_server_process_4real(server,
                                             options_override=options_override,
                                             standalone=standalone)

    log_info("Will now wait for server '%s' to start up."
             " Enjoy mongod's log for now!" % server.id)
    log_info(
        "\n****************************************************************"
        "***************")
    log_info("* START: tail of log file at '%s'" % server.get_log_file_path())
    log_info(
        "******************************************************************"
        "*************\n")

    log_tailer = tail_server_log(server)
    # wait until the server starts
    try:
        is_online = wait_for(server_started_predicate(server, mongod_pid),
                             timeout=SERVER_ONLINE_TIMEOUT)
    finally:
        # stop tailing
        stop_tailing(log_tailer)

    log_info(
        "\n****************************************************************"
        "***************")
    log_info("* END: tail of log file at '%s'" % server.get_log_file_path())
    log_info(
        "******************************************************************"
        "*************\n")

    if not is_online:
        raise MongoctlException("Timed out waiting for server '%s' to start. "
                                "Please tail the log file to monitor further "
                                "progress." % server.id)

    log_info("Server '%s' started successfully! (pid=%s)\n" %
             (server.id, mongod_pid))

    return mongod_pid
예제 #8
0
def start_server_process(server, options_override=None, standalone=False):

    set_server_executable_env_vars(server)
    mongod_pid = _start_server_process_4real(server, options_override=options_override,
                                             standalone=standalone)

    log_info("Will now wait for server '%s' to start up."
             " Enjoy mongod's log for now!" %
             server.id)
    log_info("\n****************************************************************"
             "***************")
    log_info("* START: tail of log file at '%s'" % server.get_log_file_path())
    log_info("******************************************************************"
             "*************\n")

    log_tailer = tail_server_log(server)
    # wait until the server starts
    try:
        is_online = wait_for(server_started_predicate(server, mongod_pid),
                             timeout=SERVER_ONLINE_TIMEOUT)
    finally:
        # stop tailing
        stop_tailing(log_tailer)

    log_info("\n****************************************************************"
             "***************")
    log_info("* END: tail of log file at '%s'" % server.get_log_file_path())
    log_info("******************************************************************"
             "*************\n")

    if not is_online:
        raise MongoctlException("Timed out waiting for server '%s' to start. "
                                "Please tail the log file to monitor further "
                                "progress." %
                                server.id)

    log_info("Server '%s' started successfully! (pid=%s)\n" %
             (server.id, mongod_pid))

    return mongod_pid