Ejemplo n.º 1
0
 def show_options(self):
     """ Show all audit log variables.
     """
     server = Server({'conn_info': self.options.get("server_vals", None)})
     server.connect()
     rows = server.show_server_variable("audit%")
     server.disconnect()
     if rows:
         print "#\n# Audit Log Variables and Options\n#"
         print_list(sys.stdout, "GRID", ['Variable_name', 'Value'], rows)
         print
     else:
         raise UtilError("No audit log variables found.")
Ejemplo n.º 2
0
 def show_options(self):
     """ Show all audit log variables.
     """
     server = Server({'conn_info': self.options.get("server_vals", None)})
     server.connect()
     rows = server.show_server_variable("audit%")
     server.disconnect()
     if rows:
         print "#\n# Audit Log Variables and Options\n#"
         print_list(sys.stdout, "GRID", ['Variable_name', 'Value'],
                    rows)
         print
     else:
         raise UtilError("No audit log variables found.")
Ejemplo n.º 3
0
def _shutdown_running_servers(server_list, processes, basedir):
    """Shutdown any running servers.

    processes[in]       The list of processes to shutdown with the form:
                        (process_id, [datadir|port])
    basedir[in]         The starting path to search for mysqladmin tool

    Returns bool - True - servers shutdown attempted
                   False - no servers to shutdown
    """

    if len(processes) < 1:
        return False
    for process in processes:
        datadir = os.getcwd()
        connection = {
            "user": "******",
            "passwd": "root",
            "host": "localhost",
            "port": None,
            "unix_socket": None
        }
        if os.name == "posix":
            connection["unix_socket"] = os.path.join(process[1], "mysql.sock")
        elif os.name == "nt":
            connection["port"] = process[1]

        if os.name == "posix":
            print("  Process id: %6d, Data path: %s" % \
                   (int(process[0]), process[1]))
        elif os.name == "nt":
            print("  Process id: %6d, Port: %s" % \
                   (int(process[0]), process[1]))

        # 1) connect to the server.
        server_options = {
            'conn_info': connection,
        }
        svr = Server(server_options)
        ok_to_shutdown = True
        try:
            svr.connect()
        except:  # if we cannot connect, don't try to shut it down.
            ok_to_shutdown = False
            print("    WARNING: shutdown failed - cannot connect.")
        if not ok_to_shutdown and os.name == "posix":
            # Attempt kill
            os.system("kill -9 %s" % process[0])

        # 2) if nt, verify datadirectory
        if os.name == "nt" and ok_to_shutdown:
            res = svr.show_server_variable("datadir")
            server_datadir = res[0][1]
            ok_to_shudown = (server_datadir.find(datadir) >= 0)

        # 3) call shutdown method from mutlib Server_list class
        if ok_to_shutdown and svr:
            try:
                server_list.stop_server(svr)
            except MUTLibError:
                _, e, _ = sys.exc_info()
                print("    WARNING: shutdown failed: " + e.errmsg)
    return True
Ejemplo n.º 4
0
        if conn_val["port"] is not None:
            conn_val["port"] = int(conn_val["port"])
        else:
            conn_val["port"] = 0

        server_options = {
            'conn_info': conn_val,
            'role': "server%d" % i,
        }
        conn = Server(server_options)
        try:
            conn.connect()
            server_list.add_new_server(conn)
            print("CONNECTED")
            res = conn.show_server_variable("basedir")
            #print res
            basedir = res[0][1]
        # Here we capture any exception and print the error message.
        # Since all util errors (exceptions) derive from Exception, this is
        # safe.
        except Exception:
            _, err, _ = sys.exc_info()
            print("%sFAILED%s" % (BOLD_ON, BOLD_OFF))
            if conn.connect_error is not None:
                print(conn.connect_error)
            print("ERROR: %s" % str(err))
    if server_list.num_servers() == 0:
        print("ERROR: Failed to connect to any servers listed.")
        sys.exit(1)
Ejemplo n.º 5
0
def _shutdown_running_servers(server_list, processes, basedir):
    """Shutdown any running servers.

    processes[in]       The list of processes to shutdown with the form:
                        (process_id, [datadir|port])
    basedir[in]         The starting path to search for mysqladmin tool

    Returns bool - True - servers shutdown attempted
                   False - no servers to shutdown
    """

    if len(processes) < 1:
        return False
    for process in processes:
        datadir = os.getcwd()
        connection = {
            "user"   : "root",
            "passwd" : "root",
            "host"   : "localhost",
            "port"   : None,
            "unix_socket" : None
        }
        if os.name == "posix":
            connection["unix_socket"] = os.path.join(process[1], "mysql.sock")
        elif os.name == "nt":
            connection["port"] = process[1]

        if os.name == "posix":
            print("  Process id: %6d, Data path: %s" % \
                   (int(process[0]), process[1]))
        elif os.name == "nt":
            print("  Process id: %6d, Port: %s" % \
                   (int(process[0]), process[1]))

        # 1) connect to the server.
        server_options = {
            'conn_info' : connection,
        }
        svr = Server(server_options)
        ok_to_shutdown = True
        try:
            svr.connect()
        except:  # if we cannot connect, don't try to shut it down.
            ok_to_shutdown = False
            print("    WARNING: shutdown failed - cannot connect.")
        if not ok_to_shutdown and os.name == "posix":
            # Attempt kill
            os.system("kill -9 %s" % process[0])

        # 2) if nt, verify datadirectory
        if os.name == "nt" and ok_to_shutdown:
            res = svr.show_server_variable("datadir")
            server_datadir = res[0][1]
            ok_to_shudown = (server_datadir.find(datadir) >= 0)

        # 3) call shutdown method from mutlib Server_list class
        if ok_to_shutdown and svr:
            try:
                server_list.stop_server(svr)
            except MUTLibError:
                _, e, _ = sys.exc_info()
                print("    WARNING: shutdown failed: " + e.errmsg)
    return True
Ejemplo n.º 6
0
        if conn_val["port"] is not None:
            conn_val["port"] = int(conn_val["port"])
        else:
            conn_val["port"] = 0

        server_options = {
            'conn_info' : conn_val,
            'role'      : "server%d" % i,
        }
        conn = Server(server_options)
        try:
            conn.connect()
            server_list.add_new_server(conn)
            print("CONNECTED")
            res = conn.show_server_variable("basedir")
            #print res
            basedir = res[0][1]
        # Here we capture any exception and print the error message.
        # Since all util errors (exceptions) derive from Exception, this is
        # safe.
        except Exception:
            _, err, _ = sys.exc_info()
            print("%sFAILED%s" % (BOLD_ON, BOLD_OFF))
            if conn.connect_error is not None:
                print(conn.connect_error)
            print("ERROR: %s" % str(err))
    if server_list.num_servers() == 0:
        print("ERROR: Failed to connect to any servers listed.")
        sys.exit(1)
Ejemplo n.º 7
0
def _shutdown_running_servers(server_list, processes, basedir):
    """Shutdown any running servers.

    processes[in]       The list of processes to shutdown with the form:
                        (process_id, [datadir|port])
    basedir[in]         The starting path to search for mysqladmin tool

    Returns bool - True - servers shutdown attempted
                   False - no servers to shutdown
    """
    if len(processes) < 1:
        return False
    for process in processes:
        datadir = os.getcwd()
        connection = {
            "user": "******",
            "passwd": "root",
            "host": "localhost",
            "port": None,
        }
        if os.name == "posix":
            try:
                connection["port"] = get_port(process[0])
            except MUTLibError:
                connection["port"] = -1  # try to kill it forcefully later
        elif os.name == "nt":
            connection["port"] = process[1]

        if os.name == "posix":
            print("  Process id: {0:>6}, Data path: {1}".format(process[0],
                                                                process[1]))
        elif os.name == "nt":
            print("  Process id: {0:>6}, Port: {1}".format(process[0],
                                                           process[1]))

        # 1) connect to the server.
        server_options = {
            'conn_info': connection,
        }
        svr = Server(server_options)
        ok_to_shutdown = True
        try:
            svr.connect()
        except UtilError:  # if we cannot connect, don't try to shut it down.
            ok_to_shutdown = False
            print("    WARNING: shutdown failed - cannot connect.")
        if not ok_to_shutdown:
            if os.name == "posix":
                # Attempt kill
                ret_code = subprocess.call(["kill", "-9",
                                            " {0}".format(process[0])])
                # wait until connection is closed
                for _ in range(CONNECTION_CLOSE_WAIT_TIMEOUT):
                    try:
                        sock = socket.create_connection((svr.host, svr.port))
                        sock.close()
                        time.sleep(1)
                    except socket.error:
                        # could not connect, connection is closed
                        break
                else:
                    print("    WARNING: timeout waiting for connection to "
                          "process {0} to close".format(process[0]))
                if ret_code:
                    print("    WARNING: shutdown failed: Killing process {0}"
                          "returned error code {1}".format(process[0],
                                                           ret_code))
            else:
                ret_code = subprocess.call("taskkill /F /T /PID {0}".format(
                    process[0]))
                if ret_code not in (0, 128):
                    print("    WARNING: shutdown failed: Killing process {0} "
                          "returned error code {1}".format(process[0],
                                                           ret_code))
        # 2) if nt, verify datadirectory
        if os.name == "nt" and ok_to_shutdown:
            res = svr.show_server_variable("datadir")
            server_datadir = res[0][1]
            ok_to_shutdown = (server_datadir.find(datadir) >= 0)

        # 3) call shutdown method from mutlib Server_list class
        if ok_to_shutdown and svr:
            try:
                server_list.stop_server(svr)
            except MUTLibError:
                _, e, _ = sys.exc_info()
                print("    WARNING: shutdown failed: " + e.errmsg)
    return True
Ejemplo n.º 8
0
def _shutdown_running_servers(server_list, processes, basedir):
    """Shutdown any running servers.

    processes[in]       The list of processes to shutdown with the form:
                        (process_id, [datadir|port])
    basedir[in]         The starting path to search for mysqladmin tool

    Returns bool - True - servers shutdown attempted
                   False - no servers to shutdown
    """
    if len(processes) < 1:
        return False
    for process in processes:
        datadir = os.getcwd()
        connection = {
            "user": "******",
            "passwd": "root",
            "host": "localhost",
            "port": None,
        }
        if os.name == "posix":
            try:
                connection["port"] = get_port(process[0])
            except MUTLibError:
                connection["port"] = -1  # try to kill it forcefully later
        elif os.name == "nt":
            connection["port"] = process[1]

        if os.name == "posix":
            print("  Process id: {0:>6}, Data path: {1}".format(process[0],
                                                                process[1]))
        elif os.name == "nt":
            print("  Process id: {0:>6}, Port: {1}".format(process[0],
                                                           process[1]))

        # 1) connect to the server.
        server_options = {
            'conn_info': connection,
        }
        svr = Server(server_options)
        ok_to_shutdown = True
        try:
            svr.connect()
        except UtilError:  # if we cannot connect, don't try to shut it down.
            ok_to_shutdown = False
            print("    WARNING: shutdown failed - cannot connect.")
        if not ok_to_shutdown:
            if os.name == "posix":
                # Attempt kill
                ret_code = subprocess.call(["kill", "-9",
                                            " {0}".format(process[0])])
                # wait until connection is closed
                for _ in range(CONNECTION_CLOSE_WAIT_TIMEOUT):
                    try:
                        sock = socket.create_connection((svr.host, svr.port))
                        sock.close()
                        time.sleep(1)
                    except socket.error:
                        # could not connect, connection is closed
                        break
                else:
                    print("    WARNING: timeout waiting for connection to "
                          "process {0} to close".format(process[0]))
                if ret_code:
                    print("    WARNING: shutdown failed: Killing process {0}"
                          "returned error code {1}".format(process[0],
                                                           ret_code))
            else:
                ret_code = subprocess.call("taskkill /F /T /PID {0}".format(
                    process[0]))
                if ret_code not in (0, 128):
                    print("    WARNING: shutdown failed: Killing process {0} "
                          "returned error code {1}".format(process[0],
                                                           ret_code))
        # 2) if nt, verify datadirectory
        if os.name == "nt" and ok_to_shutdown:
            res = svr.show_server_variable("datadir")
            server_datadir = res[0][1]
            ok_to_shutdown = (server_datadir.find(datadir) >= 0)

        # 3) call shutdown method from mutlib Server_list class
        if ok_to_shutdown and svr:
            try:
                server_list.stop_server(svr)
            except MUTLibError:
                _, e, _ = sys.exc_info()
                print("    WARNING: shutdown failed: " + e.errmsg)
    return True